| 1 | /*********************************************************************** |
| 2 | |
| 3 | Copyright (c) 1995, 2019, Oracle and/or its affiliates. All Rights Reserved. |
| 4 | Copyright (c) 2009, Percona Inc. |
| 5 | Copyright (c) 2013, 2022, MariaDB Corporation. |
| 6 | |
| 7 | Portions of this file contain modifications contributed and copyrighted |
| 8 | by Percona Inc.. Those modifications are |
| 9 | gratefully acknowledged and are described briefly in the InnoDB |
| 10 | documentation. The contributions by Percona Inc. are incorporated with |
| 11 | their permission, and subject to the conditions contained in the file |
| 12 | COPYING.Percona. |
| 13 | |
| 14 | This program is free software; you can redistribute it and/or modify it |
| 15 | under the terms of the GNU General Public License as published by the |
| 16 | Free Software Foundation; version 2 of the License. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
| 21 | Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License along with |
| 24 | this program; if not, write to the Free Software Foundation, Inc., |
| 25 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA |
| 26 | |
| 27 | ***********************************************************************/ |
| 28 | |
| 29 | /**************************************************//** |
| 30 | @file os/os0file.cc |
| 31 | The interface to the operating system file i/o primitives |
| 32 | |
| 33 | Created 10/21/1995 Heikki Tuuri |
| 34 | *******************************************************/ |
| 35 | |
| 36 | #include "os0file.h"cxx . . $ `<file>/storage/innobase/include/os0file.h`/ |
| 37 | #include "sql_const.h"cxx . . $ `<file>/sql/sql_const.h`/ |
| 38 | #include "log.h"cxx . . $ `<file>/sql/log.h`/ |
| 39 | |
| 40 | #ifdef __linux__cxx . . $ `<built-in>:465:9`! |
| 41 | # include <sys/types.h> |
| 42 | # include <sys/stat.h> |
| 43 | # include <sys/sysmacros.h> |
| 44 | #endif |
| 45 | |
| 46 | #include "srv0mon.h"cxx . . $ `<file>/storage/innobase/include/srv0mon.h`/ |
| 47 | #include "srv0srv.h"cxx . . $ `<file>/storage/innobase/include/srv0srv.h`/ |
| 48 | #include "srv0start.h"cxx . . $ `<file>/storage/innobase/include/srv0start.h`/ |
| 49 | #include "fil0fil.h"cxx . . $ `<file>/storage/innobase/include/fil0fil.h`/ |
| 50 | #include "fsp0fsp.h"cxx . . $ `<file>/storage/innobase/include/fsp0fsp.h`/ |
| 51 | #include "buf0dblwr.h"cxx . . $ `<file>/storage/innobase/include/buf0dblwr.h`/ |
| 52 | |
| 53 | #include <tpool_structs.h>cxx . . $ `<file>/tpool/tpool_structs.h`/ |
| 54 | |
| 55 | #ifdef HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZEcxx . . $ `/build/tmp.NxIY9EeyJN/package/build/include/my_config.h:190:9`! |
| 56 | # include <fcntl.h> |
| 57 | # include <linux/falloc.h> |
| 58 | #endif /* HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE */ |
| 59 | |
| 60 | #ifdef _WIN32 |
| 61 | # include <winioctl.h> |
| 62 | #elif !defined O_DSYNCcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:156:10`! |
| 63 | # define O_DSYNC O_SYNC |
| 64 | #else |
| 65 | # include <unistd.h> |
| 66 | #endif |
| 67 | |
| 68 | // my_test_if_atomic_write(), my_win_file_secattr() |
| 69 | #include <my_sys.h>cxx . . $ `<file>/include/my_sys.h`/ |
| 70 | |
| 71 | #include <thread> |
| 72 | #include <chrono> |
| 73 | |
| 74 | /* Per-IO operation environment*/ |
| 75 | class io_slotscxx . . $ io_slots# |
| 76 | { |
| 77 | private: |
| 78 | tpoolcxx . . $ tpool/::cachecxx . . $ tpool/cache#<tpoolcxx . . $ tpool/::aiocbcxx . . $ tpool/aiocb#, true> m_cachecxx . . $ io_slots#m_cache.; |
| 79 | tpoolcxx . . $ tpool/::task_groupcxx . . $ tpool/task_group# m_groupcxx . . $ io_slots#m_group.; |
| 80 | int m_max_aiocxx . . $ io_slots#m_max_aio.; |
| 81 | public: |
| 82 | io_slotscxx . . $ io_slots#io_slots(3e454b8ccf442868).(int max_submitted_io, int max_callback_concurrency) : |
| 83 | m_cachecxx . . $ io_slots#m_cache.(max_submitted_io), m_groupcxx . . $ io_slots#m_group.(max_callback_concurrency, false), |
| 84 | m_max_aiocxx . . $ io_slots#m_max_aio.(max_submitted_io) |
| 85 | { |
| 86 | } |
| 87 | /* Get cached AIO control block */ |
| 88 | tpoolcxx . . $ tpool/::aiocbcxx . . $ tpool/aiocb#* acquirecxx . . $ io_slots#acquire(8b2b19b7e814d8a1).() |
| 89 | { |
| 90 | return m_cachecxx . . $ io_slots#m_cache..getcxx . . $ tpool/cache#get(155dc7f103cdb9db).(); |
| 91 | } |
| 92 | /* Release AIO control block back to cache */ |
| 93 | void releasecxx . . $ io_slots#release(38968c151d7b843b).(tpoolcxx . . $ tpool/::aiocbcxx . . $ tpool/aiocb#* aiocb) |
| 94 | { |
| 95 | m_cachecxx . . $ io_slots#m_cache..putcxx . . $ tpool/cache#put(ebd0a1552f8ce24f).(aiocb); |
| 96 | } |
| 97 | |
| 98 | bool containscxx . . $ io_slots#contains(2337cc53e9a7e7cb).(tpoolcxx . . $ tpool/::aiocbcxx . . $ tpool/aiocb#* aiocb) |
| 99 | { |
| 100 | return m_cachecxx . . $ io_slots#m_cache..containscxx . . $ tpool/cache#contains(4a2ab88644057ef5).(aiocb); |
| 101 | } |
| 102 | |
| 103 | /* Wait for completions of all AIO operations */ |
| 104 | void waitcxx . . $ io_slots#wait(f38159257778c065).(stdcxx . . $ std/::unique_lockcxx . . $ std/unique_lock#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> &lk) |
| 105 | { |
| 106 | m_cachecxx . . $ io_slots#m_cache..waitcxx . . $ tpool/cache#wait(f38159257778c065).(lk); |
| 107 | } |
| 108 | |
| 109 | void waitcxx . . $ io_slots#wait(49f6e7a06ebc5aa8).() |
| 110 | { |
| 111 | m_cachecxx . . $ io_slots#m_cache..waitcxx . . $ tpool/cache#wait(49f6e7a06ebc5aa8).(); |
| 112 | } |
| 113 | |
| 114 | size_t pending_io_countcxx . . $ io_slots#pending_io_count(f708dce9a8856c70).() |
| 115 | { |
| 116 | return m_cachecxx . . $ io_slots#m_cache..poscxx . . $ tpool/cache#pos(f708dce9a8856c70).(); |
| 117 | } |
| 118 | |
| 119 | stdcxx . . $ std/::chronocxx . . $ std/chrono/::durationcxx . . $ std/chrono/duration#<double> wait_timecxx . . $ io_slots#wait_time(fea973cbfe56c066).() |
| 120 | { |
| 121 | return m_cachecxx . . $ io_slots#m_cache..wait_timecxx . . $ tpool/cache#wait_time(fea973cbfe56c066).(); |
| 122 | } |
| 123 | |
| 124 | tpoolcxx . . $ tpool/::task_groupcxx . . $ tpool/task_group#* get_task_groupcxx . . $ io_slots#get_task_group(91bc7f57de24ed43).() |
| 125 | { |
| 126 | return &m_groupcxx . . $ io_slots#m_group.; |
| 127 | } |
| 128 | |
| 129 | ~cxx . . $ io_slots#`~io_slots`(ced63f7c635d850d).io_slotscxx . . $ io_slots#() |
| 130 | { |
| 131 | waitcxx . . $ io_slots#wait(49f6e7a06ebc5aa8).(); |
| 132 | } |
| 133 | |
| 134 | stdcxx . . $ std/::mutexcxx . . $ std/mutex# &mutexcxx . . $ io_slots#mutex(68c794e33b20812e).() |
| 135 | { |
| 136 | return m_cachecxx . . $ io_slots#m_cache..mutexcxx . . $ tpool/cache#mutex(68c794e33b20812e).(); |
| 137 | } |
| 138 | |
| 139 | void resizecxx . . $ io_slots#resize(3e454b8ccf442868).(int max_submitted_io, int max_callback_concurrency) |
| 140 | { |
| 141 | m_cachecxx . . $ io_slots#m_cache..resizecxx . . $ tpool/cache#resize(2c44cd906ae4e829).(max_submitted_io); |
| 142 | m_groupcxx . . $ io_slots#m_group..set_max_taskscxx . . $ tpool/task_group#set_max_tasks(cb2f890c2fdad230).(max_callback_concurrency); |
| 143 | m_max_aiocxx . . $ io_slots#m_max_aio. = max_submitted_io; |
| 144 | } |
| 145 | |
| 146 | tpoolcxx . . $ tpool/::task_groupcxx . . $ tpool/task_group#& task_groupcxx . . $ io_slots#task_group(e3e597138b917ae1).() |
| 147 | { |
| 148 | return m_groupcxx . . $ io_slots#m_group.; |
| 149 | } |
| 150 | }; |
| 151 | |
| 152 | static io_slotscxx . . $ io_slots# *read_slotscxx . . $ read_slots.; |
| 153 | static io_slotscxx . . $ io_slots# *write_slotscxx . . $ write_slots.; |
| 154 | |
| 155 | /** |
| 156 | Statistics for asynchronous I/O |
| 157 | @param op operation type (aio_opcode::AIO_PREAD or aio_opcode::AIO_PWRITE) |
| 158 | @param stats pointer to the structure to fill |
| 159 | */ |
| 160 | void innodb_io_slots_statscxx . . $ innodb_io_slots_stats(149ad66ff19d0eaa).(tpoolcxx . . $ tpool/::aio_opcodecxx . . $ tpool/aio_opcode# op, innodb_async_io_stats_tcxx . . $ innodb_async_io_stats_t# *stats) |
| 161 | { |
| 162 | io_slotscxx . . $ io_slots# *slots= op == tpoolcxx . . $ tpool/::aio_opcodecxx . . $ tpool/aio_opcode#::AIO_PREADcxx . . $ tpool/aio_opcode#AIO_PREAD.? read_slotscxx . . $ read_slots. : write_slotscxx . . $ write_slots.; |
| 163 | |
| 164 | stats->pending_opscxx . . $ innodb_async_io_stats_t#pending_ops. = slots->pending_io_countcxx . . $ io_slots#pending_io_count(f708dce9a8856c70).(); |
| 165 | stats->slot_wait_time_seccxx . . $ innodb_async_io_stats_t#slot_wait_time_sec.= slots->wait_timecxx . . $ io_slots#wait_time(fea973cbfe56c066).().countcxx . . $ std/chrono/duration#count(8f5363d873dd4781).(); |
| 166 | slots->task_groupcxx . . $ io_slots#task_group(e3e597138b917ae1).().get_statscxx . . $ tpool/task_group#get_stats(ca5398239b51c210).(&stats->completion_statscxx . . $ innodb_async_io_stats_t#completion_stats.); |
| 167 | } |
| 168 | |
| 169 | /** Number of retries for partial I/O's */ |
| 170 | constexpr ulintcxx . . $ ulint# NUM_RETRIES_ON_PARTIAL_IOcxx . . $ NUM_RETRIES_ON_PARTIAL_IO. = 10; |
| 171 | |
| 172 | Atomic_countercxx . . $ Atomic_counter#<ulintcxx . . $ ulint#> os_n_file_readscxx . . $ os_n_file_reads.; |
| 173 | static ulintcxx . . $ ulint# os_bytes_read_since_printoutcxx . . $ os_bytes_read_since_printout.; |
| 174 | Atomic_countercxx . . $ Atomic_counter#<size_t> os_n_file_writescxx . . $ os_n_file_writes.; |
| 175 | Atomic_countercxx . . $ Atomic_counter#<size_t> os_n_fsyncscxx . . $ os_n_fsyncs.; |
| 176 | static ulintcxx . . $ ulint# os_n_file_reads_oldcxx . . $ os_n_file_reads_old.; |
| 177 | static ulintcxx . . $ ulint# os_n_file_writes_oldcxx . . $ os_n_file_writes_old.; |
| 178 | static ulintcxx . . $ ulint# os_n_fsyncs_oldcxx . . $ os_n_fsyncs_old.; |
| 179 | |
| 180 | static time_tcxx . . $ time_t# os_last_printoutcxx . . $ os_last_printout.; |
| 181 | bool os_has_said_disk_fullcxx . . $ os_has_said_disk_full.; |
| 182 | |
| 183 | /** Default Zip compression level */ |
| 184 | extern uint page_zip_levelcxx . . $ page_zip_level.; |
| 185 | |
| 186 | #ifdef UNIV_PFS_IOcxx . . $ `storage/innobase/include/univ.i:70:10`! |
| 187 | /* Keys to register InnoDB I/O with performance schema */ |
| 188 | mysql_pfs_key_tcxx . . $ mysql_pfs_key_t# innodb_data_file_keycxx . . $ innodb_data_file_key.; |
| 189 | mysql_pfs_key_tcxx . . $ mysql_pfs_key_t# innodb_temp_file_keycxx . . $ innodb_temp_file_key.; |
| 190 | #endif |
| 191 | |
| 192 | /** Handle errors for file operations. |
| 193 | @param[in] name name of a file or NULL |
| 194 | @param[in] operation operation |
| 195 | @param[in] should_abort whether to abort on an unknown error |
| 196 | @param[in] on_error_silent whether to suppress reports of non-fatal errors |
| 197 | @return true if we should retry the operation */ |
| 198 | static |
| 199 | bool |
| 200 | os_file_handle_error_cond_exitcxx . . $ os_file_handle_error_cond_exit(46800fedf44cd2c4).( |
| 201 | const char* name, |
| 202 | const char* operation, |
| 203 | bool should_abort, |
| 204 | bool on_error_silent) noexcept; |
| 205 | |
| 206 | /** Does error handling when a file operation fails. |
| 207 | @param operation name of operation that failed */ |
| 208 | static void os_file_handle_errorcxx . . $ os_file_handle_error(85c52e162fed56f9).(const char *operation) |
| 209 | { |
| 210 | os_file_handle_error_cond_exitcxx . . $ os_file_handle_error_cond_exit(46800fedf44cd2c4).(nullptr, operation, true, false); |
| 211 | } |
| 212 | |
| 213 | /** Does error handling when a file operation fails. |
| 214 | @param[in] name name of a file or NULL |
| 215 | @param[in] operation operation name that failed |
| 216 | @param[in] on_error_silent if true then don't print any message to the log. |
| 217 | @return true if we should retry the operation */ |
| 218 | static |
| 219 | bool |
| 220 | os_file_handle_error_no_exitcxx . . $ os_file_handle_error_no_exit(567fbfac950d45).( |
| 221 | const char* name, |
| 222 | const char* operation, |
| 223 | bool on_error_silent) |
| 224 | { |
| 225 | /* Don't exit in case of unknown error */ |
| 226 | return(os_file_handle_error_cond_exitcxx . . $ os_file_handle_error_cond_exit(46800fedf44cd2c4).( |
| 227 | name, operation, false, on_error_silent)); |
| 228 | } |
| 229 | |
| 230 | /** Handle RENAME error. |
| 231 | @param name old name of the file |
| 232 | @param new_name new name of the file */ |
| 233 | static void os_file_handle_rename_errorcxx . . $ os_file_handle_rename_error(2fa786934fe80e24).(const char* name, const char* new_name) |
| 234 | { |
| 235 | if (os_file_get_last_errorcxx . . $ os_file_get_last_error(19c5c1b41feeabaf).(true) != OS_FILE_DISK_FULLcxx . . $ OS_FILE_DISK_FULL.) { |
| 236 | ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Cannot rename file '" <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). name <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "' to '" |
| 237 | <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). new_name <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "'"; |
| 238 | } else if (!os_has_said_disk_fullcxx . . $ os_has_said_disk_full.) { |
| 239 | os_has_said_disk_fullcxx . . $ os_has_said_disk_full. = true; |
| 240 | /* Disk full error is reported irrespective of the |
| 241 | on_error_silent setting. */ |
| 242 | ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Full disk prevents renaming file '" |
| 243 | <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). name <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "' to '" <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). new_name <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "'"; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | |
| 248 | #ifdef _WIN32 |
| 249 | |
| 250 | /** |
| 251 | Wrapper around Windows DeviceIoControl() function. |
| 252 | |
| 253 | Works synchronously, also in case for handle opened |
| 254 | for async access (i.e with FILE_FLAG_OVERLAPPED). |
| 255 | |
| 256 | Accepts the same parameters as DeviceIoControl(),except |
| 257 | last parameter (OVERLAPPED). |
| 258 | */ |
| 259 | static |
| 260 | BOOL |
| 261 | os_win32_device_io_control( |
| 262 | HANDLE handle, |
| 263 | DWORD code, |
| 264 | LPVOID inbuf, |
| 265 | DWORD inbuf_size, |
| 266 | LPVOID outbuf, |
| 267 | DWORD outbuf_size, |
| 268 | LPDWORD bytes_returned |
| 269 | ) |
| 270 | { |
| 271 | OVERLAPPED overlapped = { 0 }; |
| 272 | overlapped.hEvent = tpool::win_get_syncio_event(); |
| 273 | BOOL result = DeviceIoControl(handle, code, inbuf, inbuf_size, outbuf, |
| 274 | outbuf_size, NULL, &overlapped); |
| 275 | |
| 276 | if (result || (GetLastError() == ERROR_IO_PENDING)) { |
| 277 | /* Wait for async io to complete */ |
| 278 | result = GetOverlappedResult(handle, &overlapped, bytes_returned, TRUE); |
| 279 | } |
| 280 | |
| 281 | return result; |
| 282 | } |
| 283 | |
| 284 | #endif |
| 285 | |
| 286 | |
| 287 | |
| 288 | /** Helper class for doing synchronous file IO. Currently, the objective |
| 289 | is to hide the OS specific code, so that the higher level functions aren't |
| 290 | peppered with #ifdef. Makes the code flow difficult to follow. */ |
| 291 | class SyncFileIOcxx . . $ SyncFileIO# |
| 292 | { |
| 293 | public: |
| 294 | /** Constructor |
| 295 | @param[in] fh File handle |
| 296 | @param[in,out] buf Buffer to read/write |
| 297 | @param[in] n Number of bytes to read/write |
| 298 | @param[in] offset Offset where to read or write */ |
| 299 | SyncFileIOcxx . . $ SyncFileIO#SyncFileIO(c657295257626a91).(os_file_tcxx . . $ os_file_t# fh, void *buf, ulintcxx . . $ ulint# n, os_offset_tcxx . . $ os_offset_t# offset) : |
| 300 | m_fhcxx . . $ SyncFileIO#m_fh.(fh), m_bufcxx . . $ SyncFileIO#m_buf.(buf), m_ncxx . . $ SyncFileIO#m_n.(static_cast<ssize_t>(n)), m_offsetcxx . . $ SyncFileIO#m_offset.(offset) |
| 301 | { ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(m_n > 0); } |
| 302 | |
| 303 | /** Do the read/write |
| 304 | @param[in] request The IO context and type |
| 305 | @return the number of bytes read/written or negative value on error */ |
| 306 | ssize_t executecxx . . $ SyncFileIO#execute(c1483fbf63a8ac4e).(const IORequestcxx . . $ IORequest# &request); |
| 307 | |
| 308 | /** Move the read/write offset up to where the partial IO succeeded. |
| 309 | @param[in] n_bytes The number of bytes to advance */ |
| 310 | void advancecxx . . $ SyncFileIO#advance(1624ee8275b10bda).(ssize_t n_bytes) |
| 311 | { |
| 312 | m_offsetcxx . . $ SyncFileIO#m_offset.+= n_bytes; |
| 313 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(m_n >= n_bytes); |
| 314 | m_ncxx . . $ SyncFileIO#m_n.-= n_bytes; |
| 315 | m_bufcxx . . $ SyncFileIO#m_buf.= reinterpret_cast<ucharcxx . . $ uchar#*>(m_bufcxx . . $ SyncFileIO#m_buf.) + n_bytes; |
| 316 | } |
| 317 | |
| 318 | private: |
| 319 | /** Open file handle */ |
| 320 | const os_file_tcxx . . $ os_file_t# m_fhcxx . . $ SyncFileIO#m_fh.; |
| 321 | /** Buffer to read/write */ |
| 322 | void *m_bufcxx . . $ SyncFileIO#m_buf.; |
| 323 | /** Number of bytes to read/write */ |
| 324 | ssize_t m_ncxx . . $ SyncFileIO#m_n.; |
| 325 | /** Offset from where to read/write */ |
| 326 | os_offset_tcxx . . $ os_offset_t# m_offsetcxx . . $ SyncFileIO#m_offset.; |
| 327 | |
| 328 | /** Do the read/write |
| 329 | @param request The IO context and type |
| 330 | @param n Number of bytes to read/write |
| 331 | @return the number of bytes read/written or negative value on error */ |
| 332 | ssize_t execute_lowcxx . . $ SyncFileIO#execute_low(9f088d5e2cd1dd9b).(const IORequestcxx . . $ IORequest#& request, ssize_t n); |
| 333 | }; |
| 334 | |
| 335 | #ifndef _WIN32 /* On Microsoft Windows, mandatory locking is used */ |
| 336 | /** Obtain an exclusive lock on a file. |
| 337 | @param fd file descriptor |
| 338 | @param name file name |
| 339 | @return 0 on success */ |
| 340 | int os_file_lockcxx . . $ os_file_lock(7e790de9bbf2a1ce).(int fd, const char *name) noexcept |
| 341 | { |
| 342 | struct flock lk; |
| 343 | |
| 344 | lk.l_type = F_WRLCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:224:10`!; |
| 345 | lk.l_whence = SEEK_SETcxx . . $ `<external>/14710646456994434043/fcntl.h:137:10`!; |
| 346 | lk.l_start = lk.l_len = 0; |
| 347 | |
| 348 | if (fcntl(fd, F_SETLKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:108:11`!, &lk) == -1) { |
| 349 | |
| 350 | ibcxx . . $ ib/::errorcxx . . $ ib/error#() |
| 351 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Unable to lock " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). name |
| 352 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " error: " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 353 | |
| 354 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`! || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EACCEScxx . . $ `<external>/8987895939074593727/errno-base.h:17:9`!) { |
| 355 | |
| 356 | ibcxx . . $ ib/::infocxx . . $ ib/info#() |
| 357 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Check that you do not already have" |
| 358 | " another mariadbd process using the" |
| 359 | " same InnoDB data or log files."; |
| 360 | } |
| 361 | |
| 362 | return(-1); |
| 363 | } |
| 364 | |
| 365 | return(0); |
| 366 | } |
| 367 | #endif /* !_WIN32 */ |
| 368 | |
| 369 | FILE *os_file_create_tmpfilecxx . . $ os_file_create_tmpfile(5a483b8a75d6a13b).() noexcept |
| 370 | { |
| 371 | FILE* file = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 372 | Filecxx . . $ File# fd = mysql_tmpfile("ib"); |
| 373 | |
| 374 | if (fd >= 0) { |
| 375 | file = my_fdopen(fd, 0, O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`!|O_TRUNCcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:56:10`!|O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`!|FILE_BINARYcxx . . $ `include/my_global.h:556:9`!, |
| 376 | MYFcxx . . $ `include/my_global.h:986:9`!(MY_WMEcxx . . $ `include/my_sys.h:57:9`!)); |
| 377 | if (!file) { |
| 378 | my_close(fd, MYFcxx . . $ `include/my_global.h:986:9`!(MY_WMEcxx . . $ `include/my_sys.h:57:9`!)); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | if (file == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 383 | |
| 384 | ibcxx . . $ ib/::errorcxx . . $ ib/error#() |
| 385 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Unable to create temporary file; errno: " |
| 386 | <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 387 | } |
| 388 | |
| 389 | return(file); |
| 390 | } |
| 391 | |
| 392 | /** Rewind file to its start, read at most size - 1 bytes from it to str, and |
| 393 | NUL-terminate str. All errors are silently ignored. This function is |
| 394 | mostly meant to be used with temporary files. |
| 395 | @param[in,out] file File to read from |
| 396 | @param[in,out] str Buffer where to read |
| 397 | @param[in] size Size of buffer */ |
| 398 | void |
| 399 | os_file_read_stringcxx . . $ os_file_read_string(b7019e50a3408e2).( |
| 400 | FILE* file, |
| 401 | char* str, |
| 402 | ulintcxx . . $ ulint# size) noexcept |
| 403 | { |
| 404 | if (size != 0) { |
| 405 | rewind(file); |
| 406 | |
| 407 | size_t flen = fread(str, 1, size - 1, file); |
| 408 | |
| 409 | str[flen] = '\0'; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | void os_file_make_data_dir_pathcxx . . $ os_file_make_data_dir_path(79dcf97cf68ec3dd).(char *data_dir_path) noexcept |
| 414 | { |
| 415 | /* Replace the period before the extension with a null byte. */ |
| 416 | char* ptr = strrchr(data_dir_path, '.'); |
| 417 | |
| 418 | if (ptr == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 419 | return; |
| 420 | } |
| 421 | |
| 422 | ptr[0] = '\0'; |
| 423 | |
| 424 | /* The tablename starts after the last slash. */ |
| 425 | ptr = strrchr(data_dir_path, '/'); |
| 426 | |
| 427 | |
| 428 | if (ptr == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 429 | return; |
| 430 | } |
| 431 | |
| 432 | ptr[0] = '\0'; |
| 433 | |
| 434 | char* tablename = ptr + 1; |
| 435 | |
| 436 | /* The databasename starts after the next to last slash. */ |
| 437 | ptr = strrchr(data_dir_path, '/'); |
| 438 | #ifdef _WIN32 |
| 439 | if (char *aptr = strrchr(data_dir_path, '\\')) { |
| 440 | if (aptr > ptr) { |
| 441 | ptr = aptr; |
| 442 | } |
| 443 | } |
| 444 | #endif |
| 445 | |
| 446 | if (ptr == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 447 | return; |
| 448 | } |
| 449 | |
| 450 | ulintcxx . . $ ulint# tablename_len = strlen(tablename); |
| 451 | |
| 452 | memmove(++ptr, tablename, tablename_len); |
| 453 | |
| 454 | ptr[tablename_len] = '\0'; |
| 455 | } |
| 456 | |
| 457 | /** Check if the path refers to the root of a drive using a pointer |
| 458 | to the last directory separator that the caller has fixed. |
| 459 | @param[in] path path name |
| 460 | @param[in] path last directory separator in the path |
| 461 | @return true if this path is a drive root, false if not */ |
| 462 | static bool os_file_is_rootcxx . . $ os_file_is_root(70cdd81ffc50ff2f).(const char *path, const char *last_slash) noexcept |
| 463 | { |
| 464 | return( |
| 465 | #ifdef _WIN32 |
| 466 | (last_slash == path + 2 && path[1] == ':') || |
| 467 | #endif /* _WIN32 */ |
| 468 | last_slash == path); |
| 469 | } |
| 470 | |
| 471 | /** Return the parent directory component of a null-terminated path. |
| 472 | Return a new buffer containing the string up to, but not including, |
| 473 | the final component of the path. |
| 474 | The path returned will not contain a trailing separator. |
| 475 | Do not return a root path, return NULL instead. |
| 476 | The final component trimmed off may be a filename or a directory name. |
| 477 | If the final component is the only component of the path, return NULL. |
| 478 | It is the caller's responsibility to free the returned string after it |
| 479 | is no longer needed. |
| 480 | @param[in] path Path name |
| 481 | @return own: parent directory of the path */ |
| 482 | static |
| 483 | char* |
| 484 | os_file_get_parent_dircxx . . $ os_file_get_parent_dir(a8b8e32347182212).( |
| 485 | const char* path) |
| 486 | { |
| 487 | /* Find the offset of the last slash */ |
| 488 | const char* last_slash = strrchr(path, '/'); |
| 489 | |
| 490 | #ifdef _WIN32 |
| 491 | if (const char *last = strrchr(path, '\\')) { |
| 492 | if (last > last_slash) { |
| 493 | last_slash = last; |
| 494 | } |
| 495 | } |
| 496 | #endif |
| 497 | |
| 498 | if (!last_slash) { |
| 499 | /* No slash in the path, return NULL */ |
| 500 | return(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 501 | } |
| 502 | |
| 503 | /* Ok, there is a slash. Is there anything after it? */ |
| 504 | const bool has_trailing_slash = last_slash[1] == '\0'; |
| 505 | |
| 506 | /* Reduce repetitive slashes. */ |
| 507 | while (last_slash > path |
| 508 | && (IF_WINcxx . . $ `include/my_global.h:97:9`!(last_slash[-1] == '\\' ||,) last_slash[-1] == '/')) { |
| 509 | last_slash--; |
| 510 | } |
| 511 | |
| 512 | /* Check for the root of a drive. */ |
| 513 | if (os_file_is_rootcxx . . $ os_file_is_root(70cdd81ffc50ff2f).(path, last_slash)) { |
| 514 | return(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 515 | } |
| 516 | |
| 517 | /* If a trailing slash prevented the first strrchr() from trimming |
| 518 | the last component of the path, trim that component now. */ |
| 519 | if (has_trailing_slash) { |
| 520 | /* Back up to the previous slash. */ |
| 521 | last_slash--; |
| 522 | while (last_slash > path |
| 523 | && (IF_WINcxx . . $ `include/my_global.h:97:9`!(last_slash[0] != '\\' &&,) |
| 524 | last_slash[0] != '/')) { |
| 525 | last_slash--; |
| 526 | } |
| 527 | |
| 528 | /* Reduce repetitive slashes. */ |
| 529 | while (last_slash > path |
| 530 | && (IF_WINcxx . . $ `include/my_global.h:97:9`!(last_slash[-1] == '\\' ||,) |
| 531 | last_slash[-1] == '/')) { |
| 532 | last_slash--; |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | /* Check for the root of a drive. */ |
| 537 | if (os_file_is_rootcxx . . $ os_file_is_root(70cdd81ffc50ff2f).(path, last_slash)) { |
| 538 | return(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 539 | } |
| 540 | |
| 541 | if (last_slash - path < 0) { |
| 542 | /* Sanity check, it prevents gcc from trying to handle this case which |
| 543 | * results in warnings for some optimized builds */ |
| 544 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 545 | } |
| 546 | |
| 547 | /* Non-trivial directory component */ |
| 548 | |
| 549 | return(mem_strduplcxx . . $ mem_strdupl(eabdfdef77619b3d).(path, ulintcxx . . $ ulint#(last_slash - path))); |
| 550 | } |
| 551 | #ifdef UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR |
| 552 | |
| 553 | /* Test the function os_file_get_parent_dir. */ |
| 554 | void |
| 555 | test_os_file_get_parent_dir( |
| 556 | const char* child_dir, |
| 557 | const char* expected_dir) noexcept |
| 558 | { |
| 559 | char* child = mem_strdup(child_dir); |
| 560 | char* expected = expected_dir == NULL ? NULL |
| 561 | : mem_strdup(expected_dir); |
| 562 | |
| 563 | char* parent = os_file_get_parent_dir(child); |
| 564 | |
| 565 | bool unexpected = (expected == NULL |
| 566 | ? (parent != NULL) |
| 567 | : (0 != strcmp(parent, expected))); |
| 568 | if (unexpected) { |
| 569 | ib::fatal() << "os_file_get_parent_dir('" << child |
| 570 | << "') returned '" << parent |
| 571 | << "', instead of '" << expected << "'."; |
| 572 | } |
| 573 | ut_free(parent); |
| 574 | ut_free(child); |
| 575 | ut_free(expected); |
| 576 | } |
| 577 | |
| 578 | /* Test the function os_file_get_parent_dir. */ |
| 579 | void |
| 580 | unit_test_os_file_get_parent_dir() noexcept |
| 581 | { |
| 582 | test_os_file_get_parent_dir("/usr/lib/a", "/usr/lib"); |
| 583 | test_os_file_get_parent_dir("/usr/", NULL); |
| 584 | test_os_file_get_parent_dir("//usr//", NULL); |
| 585 | test_os_file_get_parent_dir("usr", NULL); |
| 586 | test_os_file_get_parent_dir("usr//", NULL); |
| 587 | test_os_file_get_parent_dir("/", NULL); |
| 588 | test_os_file_get_parent_dir("//", NULL); |
| 589 | test_os_file_get_parent_dir(".", NULL); |
| 590 | test_os_file_get_parent_dir("..", NULL); |
| 591 | # ifdef _WIN32 |
| 592 | test_os_file_get_parent_dir("D:", NULL); |
| 593 | test_os_file_get_parent_dir("D:/", NULL); |
| 594 | test_os_file_get_parent_dir("D:\\", NULL); |
| 595 | test_os_file_get_parent_dir("D:/data", NULL); |
| 596 | test_os_file_get_parent_dir("D:/data/", NULL); |
| 597 | test_os_file_get_parent_dir("D:\\data\\", NULL); |
| 598 | test_os_file_get_parent_dir("D:///data/////", NULL); |
| 599 | test_os_file_get_parent_dir("D:\\\\\\data\\\\\\\\", NULL); |
| 600 | test_os_file_get_parent_dir("D:/data//a", "D:/data"); |
| 601 | test_os_file_get_parent_dir("D:\\data\\\\a", "D:\\data"); |
| 602 | test_os_file_get_parent_dir("D:///data//a///b/", "D:///data//a"); |
| 603 | test_os_file_get_parent_dir("D:\\\\\\data\\\\a\\\\\\b\\", "D:\\\\\\data\\\\a"); |
| 604 | #endif /* _WIN32 */ |
| 605 | } |
| 606 | #endif /* UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR */ |
| 607 | |
| 608 | |
| 609 | dberr_tcxx . . $ dberr_t# os_file_create_subdirs_if_neededcxx . . $ os_file_create_subdirs_if_needed(810cb64731787954).(const char *path) noexcept |
| 610 | { |
| 611 | if (srv_read_only_modecxx . . $ srv_read_only_mode.) { |
| 612 | |
| 613 | ibcxx . . $ ib/::errorcxx . . $ ib/error#() |
| 614 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "read only mode set. Can't create " |
| 615 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "subdirectories '" <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). path <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "'"; |
| 616 | |
| 617 | return(DB_READ_ONLYcxx . . $ DB_READ_ONLY.); |
| 618 | |
| 619 | } |
| 620 | |
| 621 | char* subdir = os_file_get_parent_dircxx . . $ os_file_get_parent_dir(a8b8e32347182212).(path); |
| 622 | |
| 623 | if (subdir == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 624 | /* subdir is root or cwd, nothing to do */ |
| 625 | return(DB_SUCCESScxx . . $ DB_SUCCESS.); |
| 626 | } |
| 627 | |
| 628 | /* Test if subdir exists */ |
| 629 | os_file_type_tcxx . . $ os_file_type_t# type; |
| 630 | bool subdir_exists; |
| 631 | bool success = os_file_statuscxx . . $ os_file_status(b6307a5813339b46).(subdir, &subdir_exists, &type); |
| 632 | |
| 633 | if (success && !subdir_exists) { |
| 634 | |
| 635 | /* Subdir does not exist, create it */ |
| 636 | dberr_tcxx . . $ dberr_t# err = os_file_create_subdirs_if_neededcxx . . $ os_file_create_subdirs_if_needed(810cb64731787954).(subdir); |
| 637 | |
| 638 | if (err != DB_SUCCESScxx . . $ DB_SUCCESS.) { |
| 639 | |
| 640 | ut_freecxx . . $ `storage/innobase/include/ut0new.h:1044:9`!(subdir); |
| 641 | |
| 642 | return(err); |
| 643 | } |
| 644 | |
| 645 | success = os_file_create_directorycxx . . $ os_file_create_directory(8d8444051832ba61).(subdir, false); |
| 646 | } |
| 647 | |
| 648 | ut_freecxx . . $ `storage/innobase/include/ut0new.h:1044:9`!(subdir); |
| 649 | |
| 650 | return(success ? DB_SUCCESScxx . . $ DB_SUCCESS. : DB_ERRORcxx . . $ DB_ERROR.); |
| 651 | } |
| 652 | |
| 653 | |
| 654 | |
| 655 | /** Do the read/write |
| 656 | @param[in] request The IO context and type |
| 657 | @param[in] n Number of bytes to read/write |
| 658 | @return the number of bytes read/written or negative value on error */ |
| 659 | ssize_t |
| 660 | SyncFileIOcxx . . $ SyncFileIO#::execute_lowcxx . . $ SyncFileIO#execute_low(9f088d5e2cd1dd9b).(const IORequestcxx . . $ IORequest#& request, ssize_t n) |
| 661 | { |
| 662 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(n > 0); |
| 663 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(size_t(n) <= os_file_request_size_max); |
| 664 | |
| 665 | if (request.is_readcxx . . $ IORequest#is_read(3482b152b9333168).()) |
| 666 | return IF_WINcxx . . $ `include/my_global.h:97:9`!(tpool::pread(m_fh, m_buf, n, m_offset), pread(m_fh, m_buf, n, m_offset)); |
| 667 | return IF_WINcxx . . $ `include/my_global.h:97:9`!(tpool::pwrite(m_fh, m_buf, n, m_offset), pwrite(m_fh, m_buf, n, m_offset)); |
| 668 | } |
| 669 | |
| 670 | /** Do the read/write |
| 671 | @param[in] request The IO context and type |
| 672 | @return the number of bytes read/written or negative value on error */ |
| 673 | ssize_t |
| 674 | SyncFileIOcxx . . $ SyncFileIO#::executecxx . . $ SyncFileIO#execute(c1483fbf63a8ac4e).(const IORequestcxx . . $ IORequest#& request) |
| 675 | { |
| 676 | ssize_t n_bytes= 0; |
| 677 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(m_n > 0); |
| 678 | |
| 679 | while (size_t(m_ncxx . . $ SyncFileIO#m_n.) > os_file_request_size_maxcxx . . $ os_file_request_size_max.) |
| 680 | { |
| 681 | ssize_t n_partial_bytes= execute_lowcxx . . $ SyncFileIO#execute_low(9f088d5e2cd1dd9b).(request, os_file_request_size_maxcxx . . $ os_file_request_size_max.); |
| 682 | if (n_partial_bytes < 0) |
| 683 | return n_partial_bytes; |
| 684 | n_bytes+= n_partial_bytes; |
| 685 | if (n_partial_bytes != os_file_request_size_maxcxx . . $ os_file_request_size_max.) |
| 686 | return n_bytes; |
| 687 | advancecxx . . $ SyncFileIO#advance(1624ee8275b10bda).(os_file_request_size_maxcxx . . $ os_file_request_size_max.); |
| 688 | } |
| 689 | |
| 690 | if (ssize_t n= execute_lowcxx . . $ SyncFileIO#execute_low(9f088d5e2cd1dd9b).(request, m_ncxx . . $ SyncFileIO#m_n.)) |
| 691 | { |
| 692 | if (n < 0) |
| 693 | return n; |
| 694 | n_bytes += n; |
| 695 | } |
| 696 | return n_bytes; |
| 697 | } |
| 698 | |
| 699 | #ifndef _WIN32 |
| 700 | /** Free storage space associated with a section of the file. |
| 701 | @param[in] fh Open file handle |
| 702 | @param[in] off Starting offset (SEEK_SET) |
| 703 | @param[in] len Size of the hole |
| 704 | @return DB_SUCCESS or error code */ |
| 705 | static |
| 706 | dberr_tcxx . . $ dberr_t# |
| 707 | os_file_punch_hole_posixcxx . . $ os_file_punch_hole_posix(5135d13d1110631c).( |
| 708 | os_file_tcxx . . $ os_file_t# fh, |
| 709 | os_offset_tcxx . . $ os_offset_t# off, |
| 710 | os_offset_tcxx . . $ os_offset_t# len) |
| 711 | { |
| 712 | |
| 713 | #ifdef HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZEcxx . . $ `/build/tmp.NxIY9EeyJN/package/build/include/my_config.h:190:9`! |
| 714 | const int mode = FALLOC_FL_PUNCH_HOLEcxx . . $ `<external>/12287700497710820856/falloc.h:7:9`! | FALLOC_FL_KEEP_SIZEcxx . . $ `<external>/12287700497710820856/falloc.h:6:9`!; |
| 715 | |
| 716 | int ret = fallocate(fh, mode, off, len); |
| 717 | |
| 718 | if (ret == 0) { |
| 719 | return(DB_SUCCESScxx . . $ DB_SUCCESS.); |
| 720 | } |
| 721 | |
| 722 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ENOTSUPcxx . . $ `<external>/1531017962457201737/errno.h:30:11`!) { |
| 723 | return(DB_IO_NO_PUNCH_HOLEcxx . . $ DB_IO_NO_PUNCH_HOLE.); |
| 724 | } |
| 725 | |
| 726 | ibcxx . . $ ib/::warncxx . . $ ib/warn#() |
| 727 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "fallocate(" |
| 728 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764).", FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, " |
| 729 | <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). off <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). ", " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). len <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). ") returned errno: " |
| 730 | <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 731 | |
| 732 | return(DB_IO_ERRORcxx . . $ DB_IO_ERROR.); |
| 733 | |
| 734 | #elif defined __sun__ |
| 735 | |
| 736 | // Use F_FREESP |
| 737 | |
| 738 | #endif /* HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE */ |
| 739 | |
| 740 | return(DB_IO_NO_PUNCH_HOLEcxx . . $ DB_IO_NO_PUNCH_HOLE.); |
| 741 | } |
| 742 | |
| 743 | /** Retrieves the last error number if an error occurs in a file io function. |
| 744 | The number should be retrieved before any other OS calls (because they may |
| 745 | overwrite the error number). If the number is not known to this program, |
| 746 | the OS error number + 100 is returned. |
| 747 | @param[in] report_all_errors true if we want an error message |
| 748 | printed of all errors |
| 749 | @param[in] on_error_silent true then don't print any diagnostic |
| 750 | to the log |
| 751 | @return error number, or OS error number + 100 */ |
| 752 | ulintcxx . . $ ulint# os_file_get_last_errorcxx . . $ os_file_get_last_error(19c5c1b41feeabaf).(bool report_all_errors, bool on_error_silent) |
| 753 | noexcept |
| 754 | { |
| 755 | int err = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 756 | |
| 757 | if (err == 0) { |
| 758 | return(0); |
| 759 | } |
| 760 | |
| 761 | if (report_all_errors |
| 762 | || (err != ENOSPCcxx . . $ `<external>/8987895939074593727/errno-base.h:32:9`! && err != EEXISTcxx . . $ `<external>/8987895939074593727/errno-base.h:21:9`! && err != ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`! |
| 763 | && !on_error_silent)) { |
| 764 | |
| 765 | ibcxx . . $ ib/::errorcxx . . $ ib/error#() |
| 766 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Operating system error number " |
| 767 | <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). err |
| 768 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " in a file operation."; |
| 769 | |
| 770 | if (err == EACCEScxx . . $ `<external>/8987895939074593727/errno-base.h:17:9`!) { |
| 771 | |
| 772 | ibcxx . . $ ib/::errorcxx . . $ ib/error#() |
| 773 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "The error means mariadbd does not have" |
| 774 | " the access rights to the directory."; |
| 775 | |
| 776 | } else { |
| 777 | if (strerror(err) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 778 | |
| 779 | ibcxx . . $ ib/::errorcxx . . $ ib/error#() |
| 780 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Error number " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). err <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " means '" |
| 781 | <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). strerror(err) <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "'"; |
| 782 | } |
| 783 | |
| 784 | ibcxx . . $ ib/::infocxx . . $ ib/info#() <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). OPERATING_SYSTEM_ERROR_MSGcxx . . $ OPERATING_SYSTEM_ERROR_MSG.; |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | switch (err) { |
| 789 | case ENOSPCcxx . . $ `<external>/8987895939074593727/errno-base.h:32:9`!: |
| 790 | return(OS_FILE_DISK_FULLcxx . . $ OS_FILE_DISK_FULL.); |
| 791 | case ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!: |
| 792 | return(OS_FILE_NOT_FOUNDcxx . . $ OS_FILE_NOT_FOUND.); |
| 793 | case EEXISTcxx . . $ `<external>/8987895939074593727/errno-base.h:21:9`!: |
| 794 | return(OS_FILE_ALREADY_EXISTScxx . . $ OS_FILE_ALREADY_EXISTS.); |
| 795 | case EXDEVcxx . . $ `<external>/8987895939074593727/errno-base.h:22:9`!: |
| 796 | case ENOTDIRcxx . . $ `<external>/8987895939074593727/errno-base.h:24:9`!: |
| 797 | case EISDIRcxx . . $ `<external>/8987895939074593727/errno-base.h:25:9`!: |
| 798 | case EPERMcxx . . $ `<external>/8987895939074593727/errno-base.h:5:9`!: |
| 799 | return(OS_FILE_PATH_ERRORcxx . . $ OS_FILE_PATH_ERROR.); |
| 800 | case EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`!: |
| 801 | if (srv_use_native_aiocxx . . $ srv_use_native_aio.) { |
| 802 | return(OS_FILE_AIO_RESOURCES_RESERVEDcxx . . $ OS_FILE_AIO_RESOURCES_RESERVED.); |
| 803 | } |
| 804 | break; |
| 805 | case EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!: |
| 806 | if (srv_use_native_aiocxx . . $ srv_use_native_aio.) { |
| 807 | return(OS_FILE_AIO_INTERRUPTEDcxx . . $ OS_FILE_AIO_INTERRUPTED.); |
| 808 | } |
| 809 | break; |
| 810 | case EACCEScxx . . $ `<external>/8987895939074593727/errno-base.h:17:9`!: |
| 811 | return(OS_FILE_ACCESS_VIOLATIONcxx . . $ OS_FILE_ACCESS_VIOLATION.); |
| 812 | } |
| 813 | return(OS_FILE_ERROR_MAXcxx . . $ OS_FILE_ERROR_MAX. + err); |
| 814 | } |
| 815 | |
| 816 | /** Wrapper to fsync() or fdatasync() that retries the call on some errors. |
| 817 | Returns the value 0 if successful; otherwise the value -1 is returned and |
| 818 | the global variable errno is set to indicate the error. |
| 819 | @param[in] file open file handle |
| 820 | @return 0 if success, -1 otherwise */ |
| 821 | static int os_file_sync_posixcxx . . $ os_file_sync_posix(a1851578aea3f541).(os_file_tcxx . . $ os_file_t# file) noexcept |
| 822 | { |
| 823 | #if !defined(HAVE_FDATASYNCcxx . . $ `/build/tmp.NxIY9EeyJN/package/build/include/my_config.h:142:9`!) || HAVE_DECL_FDATASYNCcxx . . $ `/build/tmp.NxIY9EeyJN/package/build/include/my_config.h:143:9`! == 0 |
| 824 | auto func= fsync; |
| 825 | auto func_name= "fsync()"; |
| 826 | #else |
| 827 | auto func= fdatasync; |
| 828 | auto func_name= "fdatasync()"; |
| 829 | #endif |
| 830 | |
| 831 | ulintcxx . . $ ulint# failures= 0; |
| 832 | |
| 833 | for (;;) |
| 834 | { |
| 835 | ++cxx . . $ Atomic_counter#operator++(5f357b03ed472e5e).os_n_fsyncscxx . . $ os_n_fsyncs.; |
| 836 | |
| 837 | int ret= func(file); |
| 838 | |
| 839 | if (ret == 0) |
| 840 | return ret; |
| 841 | |
| 842 | switch (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) |
| 843 | { |
| 844 | case ENOLCKcxx . . $ `<external>/17922322188510340118/errno.h:9:9`!: |
| 845 | ++failures; |
| 846 | ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(failures < 1000); |
| 847 | |
| 848 | if (!(failures % 100)) |
| 849 | ibcxx . . $ ib/::warncxx . . $ ib/warn#() <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). func_name <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). ": No locks available; retrying"; |
| 850 | |
| 851 | stdcxx . . $ std/::this_threadcxx . . $ std/this_thread/::sleep_forcxx . . $ std/this_thread/sleep_for(fb2140da9187dddf).(stdcxx . . $ std/::chronocxx . . $ std/chrono/::millisecondscxx . . $ std/chrono/milliseconds#(200)); |
| 852 | break; |
| 853 | |
| 854 | case EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!: |
| 855 | ++failures; |
| 856 | ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(failures < 2000); |
| 857 | break; |
| 858 | |
| 859 | default: |
| 860 | ibcxx . . $ ib/::fatalcxx . . $ ib/fatal#() <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). func_name <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " returned " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 861 | } |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | /** Check the existence and type of the given file. |
| 866 | @param[in] path path name of file |
| 867 | @param[out] exists true if the file exists |
| 868 | @param[out] type Type of the file, if it exists |
| 869 | @return true if call succeeded */ |
| 870 | static |
| 871 | bool |
| 872 | os_file_status_posixcxx . . $ os_file_status_posix(b6307a5813339b46).( |
| 873 | const char* path, |
| 874 | bool* exists, |
| 875 | os_file_type_tcxx . . $ os_file_type_t#* type) noexcept |
| 876 | { |
| 877 | struct stat statinfo; |
| 878 | |
| 879 | int ret = stat(path, &statinfo); |
| 880 | |
| 881 | *exists = !ret; |
| 882 | |
| 883 | if (!ret) { |
| 884 | /* file exists, everything OK */ |
| 885 | } else if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`! || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ENOTDIRcxx . . $ `<external>/8987895939074593727/errno-base.h:24:9`! || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ENAMETOOLONGcxx . . $ `<external>/17922322188510340118/errno.h:8:9`!) { |
| 886 | /* file does not exist */ |
| 887 | return(true); |
| 888 | |
| 889 | } else { |
| 890 | /* file exists, but stat call failed */ |
| 891 | os_file_handle_error_no_exitcxx . . $ os_file_handle_error_no_exit(567fbfac950d45).(path, "stat", false); |
| 892 | return(false); |
| 893 | } |
| 894 | |
| 895 | if (S_ISDIRcxx . . $ `<external>/531885356569766532/stat.h:125:9`!(statinfo.st_mode)) { |
| 896 | *type = OS_FILE_TYPE_DIRcxx . . $ OS_FILE_TYPE_DIR.; |
| 897 | |
| 898 | } else if (S_ISLNKcxx . . $ `<external>/531885356569766532/stat.h:133:10`!(statinfo.st_mode)) { |
| 899 | *type = OS_FILE_TYPE_LINKcxx . . $ OS_FILE_TYPE_LINK.; |
| 900 | |
| 901 | } else if (S_ISREGcxx . . $ `<external>/531885356569766532/stat.h:128:9`!(statinfo.st_mode)) { |
| 902 | *type = OS_FILE_TYPE_FILEcxx . . $ OS_FILE_TYPE_FILE.; |
| 903 | } else { |
| 904 | *type = OS_FILE_TYPE_UNKNOWNcxx . . $ OS_FILE_TYPE_UNKNOWN.; |
| 905 | } |
| 906 | |
| 907 | return(true); |
| 908 | } |
| 909 | |
| 910 | bool os_file_flush_funccxx . . $ os_file_flush_func(109becb148f4ca36).(os_file_tcxx . . $ os_file_t# file) noexcept |
| 911 | { |
| 912 | if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(my_disable_sync)) return true; |
| 913 | |
| 914 | int ret; |
| 915 | |
| 916 | ret = os_file_sync_posixcxx . . $ os_file_sync_posix(a1851578aea3f541).(file); |
| 917 | |
| 918 | if (ret == 0) { |
| 919 | return(true); |
| 920 | } |
| 921 | |
| 922 | /* Since Linux returns EINVAL if the 'file' is actually a raw device, |
| 923 | we choose to ignore that error if we are using raw disks */ |
| 924 | |
| 925 | if (srv_start_raw_disk_in_usecxx . . $ srv_start_raw_disk_in_use. && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!) { |
| 926 | |
| 927 | return(true); |
| 928 | } |
| 929 | |
| 930 | ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "The OS said file flush did not succeed"; |
| 931 | |
| 932 | os_file_handle_errorcxx . . $ os_file_handle_error(85c52e162fed56f9).("flush"); |
| 933 | |
| 934 | /* It is a fatal error if a file flush does not succeed, because then |
| 935 | the database can get corrupt on disk */ |
| 936 | ut_errorcxx . . $ `storage/innobase/include/ut0dbg.h:58:9`!; |
| 937 | |
| 938 | return(false); |
| 939 | } |
| 940 | |
| 941 | /** NOTE! Use the corresponding macro os_file_create_simple(), not directly |
| 942 | this function! |
| 943 | A simple function to open or create a file. |
| 944 | @param[in] name name of the file or path as a null-terminated |
| 945 | string |
| 946 | @param[in] create_mode create mode |
| 947 | @param[in] access_type OS_FILE_READ_ONLY or OS_FILE_READ_WRITE |
| 948 | @param[in] read_only if true, read only checks are enforced |
| 949 | @param[out] success true if succeed, false if error |
| 950 | @return handle to the file, not defined if error, error number |
| 951 | can be retrieved with os_file_get_last_error */ |
| 952 | pfs_os_file_tcxx . . $ pfs_os_file_t# |
| 953 | os_file_create_simple_funccxx . . $ os_file_create_simple_func(dcffda9e86dd51f7).( |
| 954 | const char* name, |
| 955 | os_file_create_tcxx . . $ os_file_create_t# create_mode, |
| 956 | ulintcxx . . $ ulint# access_type, |
| 957 | bool read_only, |
| 958 | bool* success) noexcept |
| 959 | { |
| 960 | pfs_os_file_tcxx . . $ pfs_os_file_t# filecxx . . $ pfs_os_file_t#pfs_os_file_t(d4f767463ce0a6b3).; |
| 961 | |
| 962 | *success = false; |
| 963 | |
| 964 | int create_flag = O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`! | O_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:142:10`!; |
| 965 | |
| 966 | if (read_only) { |
| 967 | } else if (create_mode == OS_FILE_CREATEcxx . . $ OS_FILE_CREATE.) { |
| 968 | create_flag = O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`! | O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`! | O_EXCLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:50:10`! | O_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:142:10`!; |
| 969 | } else { |
| 970 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(create_mode == OS_FILE_OPEN); |
| 971 | if (access_type != OS_FILE_READ_ONLYcxx . . $ OS_FILE_READ_ONLY.) { |
| 972 | create_flag = O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`! | O_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:142:10`!; |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | if (fil_systemcxx . . $ fil_system..is_write_throughcxx . . $ fil_system_t#is_write_through(50ce9a9e25b4a850).()) create_flag |= O_DSYNCcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:156:10`!; |
| 977 | #ifdef O_DIRECTcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:146:10`! |
| 978 | int direct_flag = fil_systemcxx . . $ fil_system..is_bufferedcxx . . $ fil_system_t#is_buffered(50ce9a9e25b4a850).() ? 0 : O_DIRECTcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:146:10`!; |
| 979 | #else |
| 980 | constexpr int direct_flag = 0; |
| 981 | #endif |
| 982 | |
| 983 | for (;;) { |
| 984 | file =cxx . . $ pfs_os_file_t#`operator=`(d4f767463ce0a6b3). open(name, create_flag | direct_flag, my_umask); |
| 985 | |
| 986 | if (file ==cxx . . $ pfs_os_file_t#`operator==`(4a668f6de69bf818). -1) { |
| 987 | #ifdef O_DIRECTcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:146:10`! |
| 988 | if (direct_flag && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!) { |
| 989 | direct_flag = 0; |
| 990 | continue; |
| 991 | } |
| 992 | #endif |
| 993 | |
| 994 | if (!os_file_handle_error_no_exitcxx . . $ os_file_handle_error_no_exit(567fbfac950d45).( |
| 995 | name, |
| 996 | create_mode == OS_FILE_CREATEcxx . . $ OS_FILE_CREATE. |
| 997 | ? "create" : "open", false)) { |
| 998 | break; |
| 999 | } |
| 1000 | } else { |
| 1001 | *success = true; |
| 1002 | break; |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | if (!read_only |
| 1007 | && *success |
| 1008 | && access_type == OS_FILE_READ_WRITEcxx . . $ OS_FILE_READ_WRITE. |
| 1009 | && !my_disable_locking |
| 1010 | && os_file_lockcxx . . $ os_file_lock(7e790de9bbf2a1ce).(file, name)) { |
| 1011 | |
| 1012 | *success = false; |
| 1013 | close(file); |
| 1014 | file =cxx . . $ pfs_os_file_t#`operator=`(d4f767463ce0a6b3). -1; |
| 1015 | } |
| 1016 | |
| 1017 | return(file); |
| 1018 | } |
| 1019 | |
| 1020 | bool os_file_create_directorycxx . . $ os_file_create_directory(8d8444051832ba61).(const char *pathname, bool fail_if_exists) |
| 1021 | noexcept |
| 1022 | { |
| 1023 | int rcode; |
| 1024 | |
| 1025 | rcode = mkdir(pathname, 0770); |
| 1026 | |
| 1027 | if (!(rcode == 0 || (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EEXISTcxx . . $ `<external>/8987895939074593727/errno-base.h:21:9`! && !fail_if_exists))) { |
| 1028 | /* failure */ |
| 1029 | os_file_handle_error_no_exitcxx . . $ os_file_handle_error_no_exit(567fbfac950d45).(pathname, "mkdir", false); |
| 1030 | |
| 1031 | return(false); |
| 1032 | } |
| 1033 | |
| 1034 | return(true); |
| 1035 | } |
| 1036 | |
| 1037 | #ifdef O_DIRECTcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:146:10`! |
| 1038 | # ifdef __linux__cxx . . $ `<built-in>:465:9`! |
| 1039 | /** Note that the log file uses buffered I/O. */ |
| 1040 | static ATTRIBUTE_COLDcxx . . $ `include/my_compiler.h:166:10`! void os_file_log_bufferedcxx . . $ os_file_log_buffered(49f6e7a06ebc5aa8).() |
| 1041 | { |
| 1042 | log_syscxx . . $ log_sys..log_maybe_unbufferedcxx . . $ log_t#log_maybe_unbuffered.= false; |
| 1043 | log_syscxx . . $ log_sys..log_bufferedcxx . . $ log_t#log_buffered.= true; |
| 1044 | } |
| 1045 | |
| 1046 | /** @return whether the log file may work with unbuffered I/O. */ |
| 1047 | static ATTRIBUTE_COLDcxx . . $ `include/my_compiler.h:166:10`! bool os_file_log_maybe_unbufferedcxx . . $ os_file_log_maybe_unbuffered(2fde67fde93f3be0).(const struct stat &st) |
| 1048 | { |
| 1049 | char b[20 + sizeof "/sys/dev/block/" ":" "/../queue/physical_block_size"]; |
| 1050 | if (snprintf(b, sizeof b, "/sys/dev/block/%u:%u/queue/physical_block_size", |
| 1051 | majorcxx . . $ `<external>/12452211444218344808/sysmacros.h:60:9`!(st.st_dev), minorcxx . . $ `<external>/12452211444218344808/sysmacros.h:61:9`!(st.st_dev)) >= |
| 1052 | static_cast<int>(sizeof b)) |
| 1053 | return false; |
| 1054 | int f= open(b, O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!); |
| 1055 | if (f == -1) |
| 1056 | { |
| 1057 | if (snprintf(b, sizeof b, "/sys/dev/block/%u:%u/../queue/" |
| 1058 | "physical_block_size", |
| 1059 | majorcxx . . $ `<external>/12452211444218344808/sysmacros.h:60:9`!(st.st_dev), minorcxx . . $ `<external>/12452211444218344808/sysmacros.h:61:9`!(st.st_dev)) >= |
| 1060 | static_cast<int>(sizeof b)) |
| 1061 | return false; |
| 1062 | f= open(b, O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!); |
| 1063 | } |
| 1064 | unsigned long s= 0; |
| 1065 | if (f != -1) |
| 1066 | { |
| 1067 | ssize_t l= read(f, b, sizeof b); |
| 1068 | if (l > 0 && size_t(l) < sizeof b && b[l - 1] == '\n') |
| 1069 | { |
| 1070 | char *end= b; |
| 1071 | s= strtoulcxx . . $ strtoul(335a43d87d12a1b6).(b, &end, 10); |
| 1072 | if (b == end || *end != '\n') |
| 1073 | s = 0; |
| 1074 | } |
| 1075 | close(f); |
| 1076 | } |
| 1077 | if (s > 4096 || s < 64 || !ut_is_2powcxx . . $ `storage/innobase/include/ut0ut.h:98:9`!(s)) |
| 1078 | return false; |
| 1079 | log_syscxx . . $ log_sys..set_block_sizecxx . . $ log_t#set_block_size(6bab9b75950d6f3).(uint32_tcxx . . $ uint32_t#(s)); |
| 1080 | |
| 1081 | return !(st.st_size & (s - 1)); |
| 1082 | } |
| 1083 | # endif /* __linux__ */ |
| 1084 | #endif /* O_DIRECT */ |
| 1085 | |
| 1086 | /** NOTE! Use the corresponding macro os_file_create(), not directly |
| 1087 | this function! |
| 1088 | Opens an existing file or creates a new. |
| 1089 | @param[in] name name of the file or path as a null-terminated |
| 1090 | string |
| 1091 | @param[in] create_mode create mode |
| 1092 | @param[in] type OS_DATA_FILE or OS_LOG_FILE |
| 1093 | @param[in] read_only true, if read only checks should be enforcedm |
| 1094 | @param[in] success true if succeeded |
| 1095 | @return handle to the file, not defined if error, error number |
| 1096 | can be retrieved with os_file_get_last_error */ |
| 1097 | pfs_os_file_tcxx . . $ pfs_os_file_t# |
| 1098 | os_file_create_funccxx . . $ os_file_create_func(dcffda9e86dd51f7).( |
| 1099 | const char* name, |
| 1100 | os_file_create_tcxx . . $ os_file_create_t# create_mode, |
| 1101 | ulintcxx . . $ ulint# type, |
| 1102 | bool read_only, |
| 1103 | bool* success) noexcept |
| 1104 | { |
| 1105 | *success = false; |
| 1106 | |
| 1107 | DBUG_EXECUTE_IFcxx . . $ `include/my_dbug.h:172:9`!( |
| 1108 | "ib_create_table_fail_disk_full", |
| 1109 | errno = ENOSPC; |
| 1110 | return(OS_FILE_CLOSED); |
| 1111 | ); |
| 1112 | |
| 1113 | int create_flag; |
| 1114 | |
| 1115 | if (read_only) { |
| 1116 | create_flag = O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`! | O_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:142:10`!; |
| 1117 | } else if (create_mode == OS_FILE_CREATEcxx . . $ OS_FILE_CREATE. |
| 1118 | || create_mode == OS_FILE_CREATE_SILENTcxx . . $ OS_FILE_CREATE_SILENT.) { |
| 1119 | create_flag = O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`! | O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`! | O_EXCLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:50:10`! | O_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:142:10`!; |
| 1120 | } else { |
| 1121 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(create_mode == OS_FILE_OPEN |
| 1122 | || create_mode == OS_FILE_OPEN_SILENT |
| 1123 | || create_mode == OS_FILE_OPEN_RETRY |
| 1124 | || create_mode == OS_FILE_OPEN_RETRY_SILENT |
| 1125 | || create_mode == OS_FILE_OPEN_RAW); |
| 1126 | create_flag = O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`! | O_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:142:10`!; |
| 1127 | } |
| 1128 | |
| 1129 | #ifdef O_DIRECTcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:146:10`! |
| 1130 | # ifdef __linux__cxx . . $ `<built-in>:465:9`! |
| 1131 | struct stat st; |
| 1132 | # endif |
| 1133 | ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(type == OS_LOG_FILE |
| 1134 | || type == OS_DATA_FILE || type == OS_DATA_FILE_NO_O_DIRECT); |
| 1135 | int direct_flag = 0; |
| 1136 | |
| 1137 | if (type == OS_DATA_FILEcxx . . $ OS_DATA_FILE.) { |
| 1138 | if (!fil_systemcxx . . $ fil_system..is_bufferedcxx . . $ fil_system_t#is_buffered(50ce9a9e25b4a850).()) { |
| 1139 | direct_flag = O_DIRECTcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:146:10`!; |
| 1140 | } |
| 1141 | # ifdef __linux__cxx . . $ `<built-in>:465:9`! |
| 1142 | } else if (type == OS_LOG_FILEcxx . . $ OS_LOG_FILE. && create_mode != OS_FILE_CREATEcxx . . $ OS_FILE_CREATE. |
| 1143 | && create_mode != OS_FILE_CREATE_SILENTcxx . . $ OS_FILE_CREATE_SILENT. |
| 1144 | && !log_syscxx . . $ log_sys..is_openedcxx . . $ log_t#is_opened(3482b152b9333168).()) { |
| 1145 | if (stat(name, &st)) { |
| 1146 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) { |
| 1147 | goto not_found; |
| 1148 | } |
| 1149 | log_syscxx . . $ log_sys..set_block_sizecxx . . $ log_t#set_block_size(6bab9b75950d6f3).(512); |
| 1150 | goto skip_o_direct; |
| 1151 | } else if (!os_file_log_maybe_unbufferedcxx . . $ os_file_log_maybe_unbuffered(2fde67fde93f3be0).(st) |
| 1152 | || log_syscxx . . $ log_sys..log_bufferedcxx . . $ log_t#log_buffered.) { |
| 1153 | skip_o_direct: |
| 1154 | os_file_log_bufferedcxx . . $ os_file_log_buffered(49f6e7a06ebc5aa8).(); |
| 1155 | } else { |
| 1156 | direct_flag = O_DIRECTcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:146:10`!; |
| 1157 | log_syscxx . . $ log_sys..log_maybe_unbufferedcxx . . $ log_t#log_maybe_unbuffered. = true; |
| 1158 | } |
| 1159 | # endif |
| 1160 | } |
| 1161 | #else |
| 1162 | ut_a(type == OS_LOG_FILE || type == OS_DATA_FILE); |
| 1163 | constexpr int direct_flag = 0; |
| 1164 | #endif |
| 1165 | |
| 1166 | if (read_only) { |
| 1167 | } else if (type == OS_LOG_FILEcxx . . $ OS_LOG_FILE. |
| 1168 | ? log_syscxx . . $ log_sys..log_write_throughcxx . . $ log_t#log_write_through. |
| 1169 | : fil_systemcxx . . $ fil_system..is_write_throughcxx . . $ fil_system_t#is_write_through(50ce9a9e25b4a850).()) { |
| 1170 | create_flag |= O_DSYNCcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:156:10`!; |
| 1171 | } |
| 1172 | |
| 1173 | os_file_tcxx . . $ os_file_t# file; |
| 1174 | |
| 1175 | for (;;) { |
| 1176 | file = open(name, create_flag | direct_flag, my_umask); |
| 1177 | |
| 1178 | if (file == -1) { |
| 1179 | #ifdef O_DIRECTcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:146:10`! |
| 1180 | if (direct_flag && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!) { |
| 1181 | direct_flag = 0; |
| 1182 | # ifdef __linux__cxx . . $ `<built-in>:465:9`! |
| 1183 | if (type == OS_LOG_FILEcxx . . $ OS_LOG_FILE.) { |
| 1184 | os_file_log_bufferedcxx . . $ os_file_log_buffered(49f6e7a06ebc5aa8).(); |
| 1185 | } |
| 1186 | # endif |
| 1187 | if (create_mode == OS_FILE_CREATEcxx . . $ OS_FILE_CREATE. |
| 1188 | || create_mode == OS_FILE_CREATE_SILENTcxx . . $ OS_FILE_CREATE_SILENT.) { |
| 1189 | /* Linux may create the file |
| 1190 | before rejecting the O_DIRECT. */ |
| 1191 | unlink(name); |
| 1192 | } |
| 1193 | continue; |
| 1194 | } |
| 1195 | # ifdef __linux__cxx . . $ `<built-in>:465:9`! |
| 1196 | not_found: |
| 1197 | # endif |
| 1198 | #endif |
| 1199 | if (os_file_handle_error_no_exitcxx . . $ os_file_handle_error_no_exit(567fbfac950d45).( |
| 1200 | name, (create_flag & O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`!) |
| 1201 | ? "create" : "open", |
| 1202 | create_mode & OS_FILE_ON_ERROR_SILENTcxx . . $ OS_FILE_ON_ERROR_SILENT.)) { |
| 1203 | continue; |
| 1204 | } |
| 1205 | |
| 1206 | return OS_FILE_CLOSEDcxx . . $ pfs_os_file_t#pfs_os_file_t(d4f767463ce0a6b3).; |
| 1207 | } else { |
| 1208 | *success = true; |
| 1209 | break; |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | #ifdef __linux__cxx . . $ `<built-in>:465:9`! |
| 1214 | if ((create_flag & O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`!) && type == OS_LOG_FILEcxx . . $ OS_LOG_FILE.) { |
| 1215 | if (fstat(file, &st) || !os_file_log_maybe_unbufferedcxx . . $ os_file_log_maybe_unbuffered(2fde67fde93f3be0).(st)) { |
| 1216 | os_file_log_bufferedcxx . . $ os_file_log_buffered(49f6e7a06ebc5aa8).(); |
| 1217 | } else { |
| 1218 | close(file); |
| 1219 | return os_file_create_funccxx . . $ os_file_create_func(dcffda9e86dd51f7).(name, OS_FILE_OPENcxx . . $ OS_FILE_OPEN., |
| 1220 | type, false, success); |
| 1221 | } |
| 1222 | } |
| 1223 | #endif |
| 1224 | |
| 1225 | if (!read_only |
| 1226 | && create_mode != OS_FILE_OPEN_RAWcxx . . $ OS_FILE_OPEN_RAW. |
| 1227 | && !my_disable_locking |
| 1228 | && os_file_lockcxx . . $ os_file_lock(7e790de9bbf2a1ce).(file, name)) { |
| 1229 | |
| 1230 | if (create_mode == OS_FILE_OPEN_RETRYcxx . . $ OS_FILE_OPEN_RETRY. |
| 1231 | || create_mode == OS_FILE_OPEN_RETRY_SILENTcxx . . $ OS_FILE_OPEN_RETRY_SILENT.) { |
| 1232 | ibcxx . . $ ib/::infocxx . . $ ib/info#() |
| 1233 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Retrying to lock the first data file"; |
| 1234 | |
| 1235 | for (int i = 0; i < 100; i++) { |
| 1236 | stdcxx . . $ std/::this_threadcxx . . $ std/this_thread/::sleep_forcxx . . $ std/this_thread/sleep_for(fb2140da9187dddf).( |
| 1237 | stdcxx . . $ std/::chronocxx . . $ std/chrono/::secondscxx . . $ std/chrono/seconds#(1)); |
| 1238 | |
| 1239 | if (!os_file_lockcxx . . $ os_file_lock(7e790de9bbf2a1ce).(file, name)) { |
| 1240 | *success = true; |
| 1241 | return(cxx . . $ pfs_os_file_t#pfs_os_file_t(d4f767463ce0a6b3).file); |
| 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | ibcxx . . $ ib/::infocxx . . $ ib/info#() |
| 1246 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Unable to open the first data file"; |
| 1247 | } |
| 1248 | |
| 1249 | *success = false; |
| 1250 | close(file); |
| 1251 | file = -1; |
| 1252 | } |
| 1253 | |
| 1254 | return(cxx . . $ pfs_os_file_t#pfs_os_file_t(d4f767463ce0a6b3).file); |
| 1255 | } |
| 1256 | |
| 1257 | /** NOTE! Use the corresponding macro |
| 1258 | os_file_create_simple_no_error_handling(), not directly this function! |
| 1259 | A simple function to open or create a file. |
| 1260 | @param[in] name name of the file or path as a null-terminated |
| 1261 | string |
| 1262 | @param[in] create_mode OS_FILE_CREATE or OS_FILE_OPEN |
| 1263 | @param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or |
| 1264 | OS_FILE_READ_ALLOW_DELETE; the last option |
| 1265 | is used by a backup program reading the file |
| 1266 | @param[in] read_only if true read only mode checks are enforced |
| 1267 | @param[out] success true if succeeded |
| 1268 | @return own: handle to the file, not defined if error, error number |
| 1269 | can be retrieved with os_file_get_last_error */ |
| 1270 | pfs_os_file_tcxx . . $ pfs_os_file_t# |
| 1271 | os_file_create_simple_no_error_handling_funccxx . . $ os_file_create_simple_no_error_handling_func(dcffda9e86dd51f7).( |
| 1272 | const char* name, |
| 1273 | os_file_create_tcxx . . $ os_file_create_t# create_mode, |
| 1274 | ulintcxx . . $ ulint# access_type, |
| 1275 | bool read_only, |
| 1276 | bool* success) noexcept |
| 1277 | { |
| 1278 | os_file_tcxx . . $ os_file_t# file; |
| 1279 | int create_flag = O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`! | O_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:142:10`!; |
| 1280 | |
| 1281 | *success = false; |
| 1282 | |
| 1283 | if (read_only) { |
| 1284 | } else if (create_mode == OS_FILE_CREATEcxx . . $ OS_FILE_CREATE.) { |
| 1285 | create_flag = O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`! | O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`! | O_EXCLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:50:10`! | O_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:142:10`!; |
| 1286 | } else { |
| 1287 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(create_mode == OS_FILE_OPEN); |
| 1288 | if (access_type != OS_FILE_READ_ONLYcxx . . $ OS_FILE_READ_ONLY.) { |
| 1289 | ut_acxx . . $ `storage/innobase/include/ut0dbg.h:50:9`!(access_type == OS_FILE_READ_WRITE |
| 1290 | || access_type == OS_FILE_READ_ALLOW_DELETE); |
| 1291 | |
| 1292 | create_flag = O_RDWRcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:45:9`!; |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | file = open(name, create_flag, my_umask); |
| 1297 | |
| 1298 | *success = (file != -1); |
| 1299 | |
| 1300 | if (!read_only |
| 1301 | && *success |
| 1302 | && access_type == OS_FILE_READ_WRITEcxx . . $ OS_FILE_READ_WRITE. |
| 1303 | && !my_disable_locking |
| 1304 | && os_file_lockcxx . . $ os_file_lock(7e790de9bbf2a1ce).(file, name)) { |
| 1305 | |
| 1306 | *success = false; |
| 1307 | close(file); |
| 1308 | file = -1; |
| 1309 | |
| 1310 | } |
| 1311 | |
| 1312 | return(cxx . . $ pfs_os_file_t#pfs_os_file_t(d4f767463ce0a6b3).file); |
| 1313 | } |
| 1314 | |
| 1315 | /** Deletes a file if it exists. The file has to be closed before calling this. |
| 1316 | @param[in] name file path as a null-terminated string |
| 1317 | @param[out] exist indicate if file pre-exist |
| 1318 | @return true if success */ |
| 1319 | bool |
| 1320 | os_file_delete_if_exists_funccxx . . $ os_file_delete_if_exists_func(c1ce79fc3dc965f1).( |
| 1321 | const char* name, |
| 1322 | bool* exist) |
| 1323 | { |
| 1324 | if (exist != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 1325 | *exist = true; |
| 1326 | } |
| 1327 | |
| 1328 | int ret; |
| 1329 | |
| 1330 | ret = unlink(name); |
| 1331 | |
| 1332 | if (ret != 0 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) { |
| 1333 | if (exist != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 1334 | *exist = false; |
| 1335 | } |
| 1336 | } else if (ret != 0 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) { |
| 1337 | os_file_handle_error_no_exitcxx . . $ os_file_handle_error_no_exit(567fbfac950d45).(name, "delete", false); |
| 1338 | |
| 1339 | return(false); |
| 1340 | } |
| 1341 | |
| 1342 | return(true); |
| 1343 | } |
| 1344 | |
| 1345 | /** Deletes a file. The file has to be closed before calling this. |
| 1346 | @param[in] name file path as a null-terminated string |
| 1347 | @return true if success */ |
| 1348 | bool |
| 1349 | os_file_delete_funccxx . . $ os_file_delete_func(c5f7da30cbc0f4e9).( |
| 1350 | const char* name) |
| 1351 | { |
| 1352 | int ret; |
| 1353 | |
| 1354 | ret = unlink(name); |
| 1355 | |
| 1356 | if (ret != 0) { |
| 1357 | os_file_handle_error_no_exitcxx . . $ os_file_handle_error_no_exit(567fbfac950d45).(name, "delete", FALSEcxx . . $ `include/my_global.h:477:9`!); |
| 1358 | |
| 1359 | return(false); |
| 1360 | } |
| 1361 | |
| 1362 | return(true); |
| 1363 | } |
| 1364 | |
| 1365 | /** NOTE! Use the corresponding macro os_file_rename(), not directly this |
| 1366 | function! |
| 1367 | Renames a file (can also move it to another directory). It is safest that the |
| 1368 | file is closed before calling this function. |
| 1369 | @param[in] oldpath old file path as a null-terminated string |
| 1370 | @param[in] newpath new file path |
| 1371 | @return true if success */ |
| 1372 | bool |
| 1373 | os_file_rename_funccxx . . $ os_file_rename_func(b7a7aa4a824b7595).( |
| 1374 | const char* oldpath, |
| 1375 | const char* newpath) |
| 1376 | { |
| 1377 | #ifdef UNIV_DEBUG |
| 1378 | os_file_type_t type; |
| 1379 | bool exists; |
| 1380 | |
| 1381 | /* New path must not exist. */ |
| 1382 | ut_ad(os_file_status(newpath, &exists, &type)); |
| 1383 | ut_ad(!exists); |
| 1384 | |
| 1385 | /* Old path must exist. */ |
| 1386 | ut_ad(os_file_status(oldpath, &exists, &type)); |
| 1387 | ut_ad(exists); |
| 1388 | #endif /* UNIV_DEBUG */ |
| 1389 | |
| 1390 | int ret; |
| 1391 | |
| 1392 | ret = rename(oldpath, newpath); |
| 1393 | |
| 1394 | if (ret != 0) { |
| 1395 | os_file_handle_rename_errorcxx . . $ os_file_handle_rename_error(2fa786934fe80e24).(oldpath, newpath); |
| 1396 | |
| 1397 | return(false); |
| 1398 | } |
| 1399 | |
| 1400 | return(true); |
| 1401 | } |
| 1402 | |
| 1403 | /** NOTE! Use the corresponding macro os_file_close(), not directly this |
| 1404 | function! |
| 1405 | Closes a file handle. In case of error, error number can be retrieved with |
| 1406 | os_file_get_last_error. |
| 1407 | @param[in] file Handle to close |
| 1408 | @return true if success */ |
| 1409 | bool os_file_close_funccxx . . $ os_file_close_func(83c267b20bac841a).(os_file_tcxx . . $ os_file_t# file) |
| 1410 | { |
| 1411 | int ret= close(file); |
| 1412 | |
| 1413 | if (!ret) |
| 1414 | return true; |
| 1415 | |
| 1416 | os_file_handle_errorcxx . . $ os_file_handle_error(85c52e162fed56f9).("close"); |
| 1417 | return false; |
| 1418 | } |
| 1419 | |
| 1420 | os_offset_tcxx . . $ os_offset_t# os_file_get_sizecxx . . $ os_file_get_size(a516d6ace67a1470).(os_file_tcxx . . $ os_file_t# file) noexcept |
| 1421 | { |
| 1422 | return lseek(file, 0, SEEK_ENDcxx . . $ `<external>/14710646456994434043/fcntl.h:139:10`!); |
| 1423 | } |
| 1424 | |
| 1425 | os_file_size_tcxx . . $ os_file_size_t# os_file_get_sizecxx . . $ os_file_get_size(c0749f3966822cea).(const char *filename) noexcept |
| 1426 | { |
| 1427 | struct stat s; |
| 1428 | os_file_size_tcxx . . $ os_file_size_t# file_size; |
| 1429 | |
| 1430 | int ret = stat(filename, &s); |
| 1431 | |
| 1432 | if (ret == 0) { |
| 1433 | file_size.m_total_sizecxx . . $ os_file_size_t#m_total_size. = s.st_size; |
| 1434 | /* st_blocks is in 512 byte sized blocks */ |
| 1435 | file_size.m_alloc_sizecxx . . $ os_file_size_t#m_alloc_size. = s.st_blocks * 512; |
| 1436 | } else { |
| 1437 | file_size.m_total_sizecxx . . $ os_file_size_t#m_total_size. = ~0U; |
| 1438 | file_size.m_alloc_sizecxx . . $ os_file_size_t#m_alloc_size. = (os_offset_tcxx . . $ os_offset_t#) errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 1439 | } |
| 1440 | |
| 1441 | return(file_size); |
| 1442 | } |
| 1443 | |
| 1444 | /** This function returns information about the specified file |
| 1445 | @param[in] path pathname of the file |
| 1446 | @param[out] stat_info information of a file in a directory |
| 1447 | @param[in,out] statinfo information of a file in a directory |
| 1448 | @param[in] check_rw_perm for testing whether the file can be opened |
| 1449 | in RW mode |
| 1450 | @param[in] read_only if true read only mode checks are enforced |
| 1451 | @return DB_SUCCESS if all OK */ |
| 1452 | static |
| 1453 | dberr_tcxx . . $ dberr_t# |
| 1454 | os_file_get_status_posixcxx . . $ os_file_get_status_posix(7bcea40a702707b).( |
| 1455 | const char* path, |
| 1456 | os_file_stat_tcxx . . $ os_file_stat_t#* stat_info, |
| 1457 | struct stat* statinfo, |
| 1458 | bool check_rw_perm, |
| 1459 | bool read_only) |
| 1460 | { |
| 1461 | int ret = stat(path, statinfo); |
| 1462 | |
| 1463 | if (ret && (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`! || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ENOTDIRcxx . . $ `<external>/8987895939074593727/errno-base.h:24:9`! |
| 1464 | || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ENAMETOOLONGcxx . . $ `<external>/17922322188510340118/errno.h:8:9`!)) { |
| 1465 | /* file does not exist */ |
| 1466 | |
| 1467 | return(DB_NOT_FOUNDcxx . . $ DB_NOT_FOUND.); |
| 1468 | |
| 1469 | } else if (ret) { |
| 1470 | /* file exists, but stat call failed */ |
| 1471 | |
| 1472 | os_file_handle_error_no_exitcxx . . $ os_file_handle_error_no_exit(567fbfac950d45).(path, "stat", false); |
| 1473 | |
| 1474 | return(DB_FAILcxx . . $ DB_FAIL.); |
| 1475 | } |
| 1476 | |
| 1477 | switch (statinfo->st_mode & S_IFMTcxx . . $ `<external>/531885356569766532/stat.h:104:10`!) { |
| 1478 | case S_IFDIRcxx . . $ `<external>/531885356569766532/stat.h:105:10`!: |
| 1479 | stat_info->typecxx . . $ os_file_stat_t#type. = OS_FILE_TYPE_DIRcxx . . $ OS_FILE_TYPE_DIR.; |
| 1480 | break; |
| 1481 | case S_IFLNKcxx . . $ `<external>/531885356569766532/stat.h:113:11`!: |
| 1482 | stat_info->typecxx . . $ os_file_stat_t#type. = OS_FILE_TYPE_LINKcxx . . $ OS_FILE_TYPE_LINK.; |
| 1483 | break; |
| 1484 | case S_IFBLKcxx . . $ `<external>/531885356569766532/stat.h:107:10`!: |
| 1485 | /* Handle block device as regular file. */ |
| 1486 | case S_IFCHRcxx . . $ `<external>/531885356569766532/stat.h:106:10`!: |
| 1487 | /* Handle character device as regular file. */ |
| 1488 | case S_IFREGcxx . . $ `<external>/531885356569766532/stat.h:108:10`!: |
| 1489 | stat_info->typecxx . . $ os_file_stat_t#type. = OS_FILE_TYPE_FILEcxx . . $ OS_FILE_TYPE_FILE.; |
| 1490 | break; |
| 1491 | default: |
| 1492 | stat_info->typecxx . . $ os_file_stat_t#type. = OS_FILE_TYPE_UNKNOWNcxx . . $ OS_FILE_TYPE_UNKNOWN.; |
| 1493 | } |
| 1494 | |
| 1495 | stat_info->sizecxx . . $ os_file_stat_t#size. = statinfo->st_size; |
| 1496 | stat_info->block_sizecxx . . $ os_file_stat_t#block_size. = statinfo->st_blksize; |
| 1497 | stat_info->alloc_sizecxx . . $ os_file_stat_t#alloc_size. = statinfo->st_blocks * 512; |
| 1498 | |
| 1499 | if (check_rw_perm |
| 1500 | && (stat_info->typecxx . . $ os_file_stat_t#type. == OS_FILE_TYPE_FILEcxx . . $ OS_FILE_TYPE_FILE. |
| 1501 | || stat_info->typecxx . . $ os_file_stat_t#type. == OS_FILE_TYPE_BLOCKcxx . . $ OS_FILE_TYPE_BLOCK.)) { |
| 1502 | |
| 1503 | stat_info->rw_permcxx . . $ os_file_stat_t#rw_perm. = !access(path, read_only |
| 1504 | ? R_OKcxx . . $ `<external>/12628407106812493757/unistd.h:281:9`! : R_OKcxx . . $ `<external>/12628407106812493757/unistd.h:281:9`! | W_OKcxx . . $ `<external>/12628407106812493757/unistd.h:282:9`!); |
| 1505 | } |
| 1506 | |
| 1507 | return(DB_SUCCESScxx . . $ DB_SUCCESS.); |
| 1508 | } |
| 1509 | |
| 1510 | /** Truncates a file to a specified size in bytes. |
| 1511 | Do nothing if the size to preserve is greater or equal to the current |
| 1512 | size of the file. |
| 1513 | @param[in] pathname file path |
| 1514 | @param[in] file file to be truncated |
| 1515 | @param[in] size size to preserve in bytes |
| 1516 | @return true if success */ |
| 1517 | static |
| 1518 | bool |
| 1519 | os_file_truncate_posixcxx . . $ os_file_truncate_posix(4efae755e34f93d9).( |
| 1520 | const char* pathname, |
| 1521 | os_file_tcxx . . $ os_file_t# file, |
| 1522 | os_offset_tcxx . . $ os_offset_t# size) |
| 1523 | { |
| 1524 | int res = ftruncate(file, size); |
| 1525 | |
| 1526 | if (res == -1) { |
| 1527 | |
| 1528 | bool retry; |
| 1529 | |
| 1530 | retry = os_file_handle_error_no_exitcxx . . $ os_file_handle_error_no_exit(567fbfac950d45).( |
| 1531 | pathname, "truncate", false); |
| 1532 | |
| 1533 | if (retry) { |
| 1534 | ibcxx . . $ ib/::warncxx . . $ ib/warn#() |
| 1535 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Truncate failed for '" |
| 1536 | <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). pathname <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "'"; |
| 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | return(res == 0); |
| 1541 | } |
| 1542 | |
| 1543 | bool os_file_set_eofcxx . . $ os_file_set_eof(72aa1777aa3f96db).(FILE *file) noexcept |
| 1544 | { |
| 1545 | return(!ftruncate(fileno(file), ftell(file))); |
| 1546 | } |
| 1547 | |
| 1548 | bool os_file_set_sizecxx . . $ os_file_set_size(c5e330475387994b).(const char *name, os_file_tcxx . . $ os_file_t# file, os_offset_tcxx . . $ os_offset_t# size, |
| 1549 | bool is_sparse) noexcept |
| 1550 | { |
| 1551 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!(size & 4095)); |
| 1552 | |
| 1553 | if (is_sparse) { |
| 1554 | bool success = !ftruncate(file, size); |
| 1555 | if (!success) { |
| 1556 | sql_print_errorcxx . . $ sql_print_error(326aeb464d16410c).("InnoDB: ftruncate of file %s to %" |
| 1557 | PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " bytes failed with error %d", |
| 1558 | name, size, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!); |
| 1559 | } |
| 1560 | return success; |
| 1561 | } |
| 1562 | |
| 1563 | # ifdef HAVE_POSIX_FALLOCATEcxx . . $ `/build/tmp.NxIY9EeyJN/package/build/include/my_config.h:189:9`! |
| 1564 | int err; |
| 1565 | os_offset_tcxx . . $ os_offset_t# current_size; |
| 1566 | do { |
| 1567 | current_size = os_file_get_sizecxx . . $ os_file_get_size(a516d6ace67a1470).(file); |
| 1568 | if (current_size == os_offset_tcxx . . $ os_offset_t#(-1)) { |
| 1569 | err = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 1570 | } else { |
| 1571 | if (current_size >= size) { |
| 1572 | return true; |
| 1573 | } |
| 1574 | current_size &= ~4095ULL; |
| 1575 | # ifdef __linux__cxx . . $ `<built-in>:465:9`! |
| 1576 | if (!fallocate(file, 0, current_size, |
| 1577 | size - current_size)) { |
| 1578 | err = 0; |
| 1579 | break; |
| 1580 | } |
| 1581 | |
| 1582 | err = errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 1583 | # else |
| 1584 | err = posix_fallocate(file, current_size, |
| 1585 | size - current_size); |
| 1586 | # endif |
| 1587 | } |
| 1588 | } while (err == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`! |
| 1589 | && srv_shutdown_statecxx . . $ srv_shutdown_state. <= SRV_SHUTDOWN_INITIATEDcxx . . $ SRV_SHUTDOWN_INITIATED.); |
| 1590 | |
| 1591 | switch (err) { |
| 1592 | case 0: |
| 1593 | return true; |
| 1594 | default: |
| 1595 | sql_print_errorcxx . . $ sql_print_error(326aeb464d16410c).("InnoDB: preallocating %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! |
| 1596 | " bytes for file %s failed with error %d", |
| 1597 | size, name, err); |
| 1598 | /* fall through */ |
| 1599 | case EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!: |
| 1600 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = err; |
| 1601 | return false; |
| 1602 | case EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!: |
| 1603 | case EOPNOTSUPPcxx . . $ `<external>/17922322188510340118/errno.h:79:9`!: |
| 1604 | /* fall back to the code below */ |
| 1605 | break; |
| 1606 | } |
| 1607 | # else /* HAVE_POSIX_ALLOCATE */ |
| 1608 | os_offset_t current_size = os_file_get_size(file); |
| 1609 | # endif /* HAVE_POSIX_ALLOCATE */ |
| 1610 | |
| 1611 | current_size &= ~4095ULL; |
| 1612 | |
| 1613 | if (current_size >= size) { |
| 1614 | return true; |
| 1615 | } |
| 1616 | |
| 1617 | /* Write up to 1 megabyte at a time. */ |
| 1618 | ulintcxx . . $ ulint# buf_size = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).<ulintcxx . . $ ulint#>(64, |
| 1619 | ulintcxx . . $ ulint#(size >> srv_page_size_shiftcxx . . $ srv_page_size_shift.)) |
| 1620 | << srv_page_size_shiftcxx . . $ srv_page_size_shift.; |
| 1621 | |
| 1622 | /* Align the buffer for possible raw i/o */ |
| 1623 | bytecxx . . $ byte#* buf = static_cast<bytecxx . . $ byte#*>(aligned_malloccxx . . $ aligned_malloc(63a7bf2941bfcd7a).(buf_size, |
| 1624 | srv_page_sizecxx . . $ srv_page_size.)); |
| 1625 | /* Write buffer full of zeros */ |
| 1626 | memset(buf, 0, buf_size); |
| 1627 | |
| 1628 | while (current_size < size) { |
| 1629 | ulintcxx . . $ ulint# n_bytes; |
| 1630 | |
| 1631 | if (size - current_size < (os_offset_tcxx . . $ os_offset_t#) buf_size) { |
| 1632 | n_bytes = (ulintcxx . . $ ulint#) (size - current_size); |
| 1633 | } else { |
| 1634 | n_bytes = buf_size; |
| 1635 | } |
| 1636 | |
| 1637 | if (os_file_writecxx . . $ `storage/innobase/include/os0file.h:571:10`!(IORequestWrite, name, |
| 1638 | file, buf, current_size, n_bytes) != |
| 1639 | DB_SUCCESScxx . . $ DB_SUCCESS.) { |
| 1640 | break; |
| 1641 | } |
| 1642 | |
| 1643 | current_size += n_bytes; |
| 1644 | } |
| 1645 | |
| 1646 | aligned_freecxx . . $ aligned_free(5d22bdacc48458e8).(buf); |
| 1647 | |
| 1648 | return current_size >= size && os_file_flushcxx . . $ `storage/innobase/include/os0file.h:575:10`!(file); |
| 1649 | } |
| 1650 | |
| 1651 | #else /* !_WIN32 */ |
| 1652 | |
| 1653 | #include <WinIoCtl.h> |
| 1654 | |
| 1655 | |
| 1656 | |
| 1657 | /** Free storage space associated with a section of the file. |
| 1658 | @param[in] fh Open file handle |
| 1659 | @param[in] off Starting offset (SEEK_SET) |
| 1660 | @param[in] len Size of the hole |
| 1661 | @return 0 on success or errno */ |
| 1662 | static |
| 1663 | dberr_t |
| 1664 | os_file_punch_hole_win32( |
| 1665 | os_file_t fh, |
| 1666 | os_offset_t off, |
| 1667 | os_offset_t len) |
| 1668 | { |
| 1669 | FILE_ZERO_DATA_INFORMATION punch; |
| 1670 | |
| 1671 | punch.FileOffset.QuadPart = off; |
| 1672 | punch.BeyondFinalZero.QuadPart = off + len; |
| 1673 | |
| 1674 | /* If lpOverlapped is NULL, lpBytesReturned cannot be NULL, |
| 1675 | therefore we pass a dummy parameter. */ |
| 1676 | DWORD temp; |
| 1677 | BOOL success = os_win32_device_io_control( |
| 1678 | fh, FSCTL_SET_ZERO_DATA, &punch, sizeof(punch), |
| 1679 | NULL, 0, &temp); |
| 1680 | |
| 1681 | return(success ? DB_SUCCESS: DB_IO_NO_PUNCH_HOLE); |
| 1682 | } |
| 1683 | |
| 1684 | /** Check the existence and type of the given file. |
| 1685 | @param[in] path path name of file |
| 1686 | @param[out] exists true if the file exists |
| 1687 | @param[out] type Type of the file, if it exists |
| 1688 | @return true if call succeeded */ |
| 1689 | static |
| 1690 | bool |
| 1691 | os_file_status_win32( |
| 1692 | const char* path, |
| 1693 | bool* exists, |
| 1694 | os_file_type_t* type) |
| 1695 | { |
| 1696 | int ret; |
| 1697 | struct _stat64 statinfo; |
| 1698 | |
| 1699 | ret = _stat64(path, &statinfo); |
| 1700 | |
| 1701 | *exists = !ret; |
| 1702 | |
| 1703 | if (!ret) { |
| 1704 | /* file exists, everything OK */ |
| 1705 | |
| 1706 | } else if (errno == ENOENT || errno == ENOTDIR || errno == ENAMETOOLONG) { |
| 1707 | /* file does not exist */ |
| 1708 | return(true); |
| 1709 | |
| 1710 | } else { |
| 1711 | /* file exists, but stat call failed */ |
| 1712 | os_file_handle_error_no_exit(path, "stat", false); |
| 1713 | return(false); |
| 1714 | } |
| 1715 | |
| 1716 | if (_S_IFDIR & statinfo.st_mode) { |
| 1717 | *type = OS_FILE_TYPE_DIR; |
| 1718 | |
| 1719 | } else if (_S_IFREG & statinfo.st_mode) { |
| 1720 | *type = OS_FILE_TYPE_FILE; |
| 1721 | |
| 1722 | } else { |
| 1723 | *type = OS_FILE_TYPE_UNKNOWN; |
| 1724 | } |
| 1725 | |
| 1726 | return(true); |
| 1727 | } |
| 1728 | |
| 1729 | /* Dynamically load NtFlushBuffersFileEx, used in os_file_flush_func */ |
| 1730 | #include <winternl.h> |
| 1731 | typedef NTSTATUS(WINAPI* pNtFlushBuffersFileEx)( |
| 1732 | HANDLE FileHandle, ULONG Flags, PVOID Parameters, ULONG ParametersSize, |
| 1733 | PIO_STATUS_BLOCK IoStatusBlock); |
| 1734 | |
| 1735 | static pNtFlushBuffersFileEx my_NtFlushBuffersFileEx |
| 1736 | = (pNtFlushBuffersFileEx)GetProcAddress(GetModuleHandle("ntdll"), |
| 1737 | "NtFlushBuffersFileEx"); |
| 1738 | |
| 1739 | /** NOTE! Use the corresponding macro os_file_flush(), not directly this |
| 1740 | function! |
| 1741 | Flushes the write buffers of a given file to the disk. |
| 1742 | @param[in] file handle to a file |
| 1743 | @return true if success */ |
| 1744 | bool os_file_flush_func(os_file_t file) noexcept |
| 1745 | { |
| 1746 | if (UNIV_UNLIKELY(my_disable_sync)) |
| 1747 | return true; |
| 1748 | |
| 1749 | ++os_n_fsyncs; |
| 1750 | static bool disable_datasync; |
| 1751 | |
| 1752 | if (my_NtFlushBuffersFileEx && !disable_datasync) |
| 1753 | { |
| 1754 | IO_STATUS_BLOCK iosb{}; |
| 1755 | NTSTATUS status= my_NtFlushBuffersFileEx( |
| 1756 | file, FLUSH_FLAGS_FILE_DATA_SYNC_ONLY, nullptr, 0, &iosb); |
| 1757 | if (!status) |
| 1758 | return true; |
| 1759 | /* |
| 1760 | NtFlushBuffersFileEx(FLUSH_FLAGS_FILE_DATA_SYNC_ONLY) might fail |
| 1761 | unless on Win10+, and maybe non-NTFS. Switch to using FlushFileBuffers(). |
| 1762 | */ |
| 1763 | disable_datasync= true; |
| 1764 | } |
| 1765 | |
| 1766 | if (FlushFileBuffers(file)) |
| 1767 | return true; |
| 1768 | |
| 1769 | /* Since Windows returns ERROR_INVALID_FUNCTION if the 'file' is |
| 1770 | actually a raw device, we choose to ignore that error if we are using |
| 1771 | raw disks */ |
| 1772 | if (srv_start_raw_disk_in_use && GetLastError() == ERROR_INVALID_FUNCTION) |
| 1773 | return true; |
| 1774 | |
| 1775 | os_file_handle_error("flush"); |
| 1776 | |
| 1777 | /* It is a fatal error if a file flush does not succeed, because then |
| 1778 | the database can get corrupt on disk */ |
| 1779 | ut_error; |
| 1780 | |
| 1781 | return false; |
| 1782 | } |
| 1783 | |
| 1784 | /** Retrieves the last error number if an error occurs in a file io function. |
| 1785 | The number should be retrieved before any other OS calls (because they may |
| 1786 | overwrite the error number). If the number is not known to this program, |
| 1787 | then OS error number + OS_FILE_ERROR_MAX is returned. |
| 1788 | @param[in] report_all_errors true if we want an error message |
| 1789 | printed of all errors |
| 1790 | @param[in] on_error_silent true then don't print any diagnostic |
| 1791 | to the log |
| 1792 | @return error number, or OS error number + OS_FILE_ERROR_MAX */ |
| 1793 | ulint os_file_get_last_error(bool report_all_errors, bool on_error_silent) |
| 1794 | noexcept |
| 1795 | { |
| 1796 | ulint err = (ulint) GetLastError(); |
| 1797 | |
| 1798 | if (err == ERROR_SUCCESS) { |
| 1799 | return(0); |
| 1800 | } |
| 1801 | |
| 1802 | if (report_all_errors |
| 1803 | || (!on_error_silent |
| 1804 | && err != ERROR_DISK_FULL |
| 1805 | && err != ERROR_FILE_NOT_FOUND |
| 1806 | && err != ERROR_FILE_EXISTS)) { |
| 1807 | |
| 1808 | ib::error() |
| 1809 | << "Operating system error number " << err |
| 1810 | << " in a file operation."; |
| 1811 | |
| 1812 | switch (err) { |
| 1813 | case ERROR_PATH_NOT_FOUND: |
| 1814 | break; |
| 1815 | case ERROR_ACCESS_DENIED: |
| 1816 | ib::error() |
| 1817 | << "The error means mariadbd does not have" |
| 1818 | " the access rights to" |
| 1819 | " the directory. It may also be" |
| 1820 | " you have created a subdirectory" |
| 1821 | " of the same name as a data file."; |
| 1822 | break; |
| 1823 | case ERROR_SHARING_VIOLATION: |
| 1824 | case ERROR_LOCK_VIOLATION: |
| 1825 | ib::error() |
| 1826 | << "The error means that another program" |
| 1827 | " is using InnoDB's files." |
| 1828 | " This might be a backup or antivirus" |
| 1829 | " software or another instance" |
| 1830 | " of MariaDB." |
| 1831 | " Please close it to get rid of this error."; |
| 1832 | break; |
| 1833 | case ERROR_WORKING_SET_QUOTA: |
| 1834 | case ERROR_NO_SYSTEM_RESOURCES: |
| 1835 | ib::error() |
| 1836 | << "The error means that there are no" |
| 1837 | " sufficient system resources or quota to" |
| 1838 | " complete the operation."; |
| 1839 | break; |
| 1840 | case ERROR_OPERATION_ABORTED: |
| 1841 | ib::error() |
| 1842 | << "The error means that the I/O" |
| 1843 | " operation has been aborted" |
| 1844 | " because of either a thread exit" |
| 1845 | " or an application request." |
| 1846 | " Retry attempt is made."; |
| 1847 | break; |
| 1848 | default: |
| 1849 | ib::info() << OPERATING_SYSTEM_ERROR_MSG; |
| 1850 | } |
| 1851 | } |
| 1852 | |
| 1853 | if (err == ERROR_FILE_NOT_FOUND) { |
| 1854 | return(OS_FILE_NOT_FOUND); |
| 1855 | } else if (err == ERROR_DISK_FULL) { |
| 1856 | return(OS_FILE_DISK_FULL); |
| 1857 | } else if (err == ERROR_FILE_EXISTS) { |
| 1858 | return(OS_FILE_ALREADY_EXISTS); |
| 1859 | } else if (err == ERROR_SHARING_VIOLATION |
| 1860 | || err == ERROR_LOCK_VIOLATION) { |
| 1861 | return(OS_FILE_SHARING_VIOLATION); |
| 1862 | } else if (err == ERROR_WORKING_SET_QUOTA |
| 1863 | || err == ERROR_NO_SYSTEM_RESOURCES) { |
| 1864 | return(OS_FILE_INSUFFICIENT_RESOURCE); |
| 1865 | } else if (err == ERROR_OPERATION_ABORTED) { |
| 1866 | return(OS_FILE_OPERATION_ABORTED); |
| 1867 | } else if (err == ERROR_ACCESS_DENIED) { |
| 1868 | return(OS_FILE_ACCESS_VIOLATION); |
| 1869 | } |
| 1870 | |
| 1871 | return(OS_FILE_ERROR_MAX + err); |
| 1872 | } |
| 1873 | |
| 1874 | |
| 1875 | /** NOTE! Use the corresponding macro os_file_create_simple(), not directly |
| 1876 | this function! |
| 1877 | A simple function to open or create a file. |
| 1878 | @param[in] name name of the file or path as a null-terminated |
| 1879 | string |
| 1880 | @param[in] create_mode create mode |
| 1881 | @param[in] access_type OS_FILE_READ_ONLY or OS_FILE_READ_WRITE |
| 1882 | @param[in] read_only if true read only mode checks are enforced |
| 1883 | @param[out] success true if succeed, false if error |
| 1884 | @return handle to the file, not defined if error, error number |
| 1885 | can be retrieved with os_file_get_last_error */ |
| 1886 | pfs_os_file_t |
| 1887 | os_file_create_simple_func( |
| 1888 | const char* name, |
| 1889 | os_file_create_t create_mode, |
| 1890 | ulint access_type, |
| 1891 | bool read_only, |
| 1892 | bool* success) noexcept |
| 1893 | { |
| 1894 | os_file_t file; |
| 1895 | |
| 1896 | *success = false; |
| 1897 | |
| 1898 | DWORD access = GENERIC_READ; |
| 1899 | DWORD create_flag; |
| 1900 | DWORD attributes = 0; |
| 1901 | |
| 1902 | ut_ad(srv_operation == SRV_OPERATION_NORMAL); |
| 1903 | |
| 1904 | if (read_only || create_mode == OS_FILE_OPEN) { |
| 1905 | create_flag = OPEN_EXISTING; |
| 1906 | } else { |
| 1907 | ut_ad(create_mode == OS_FILE_CREATE); |
| 1908 | create_flag = CREATE_NEW; |
| 1909 | } |
| 1910 | |
| 1911 | if (access_type == OS_FILE_READ_ONLY) { |
| 1912 | } else if (read_only) { |
| 1913 | ib::info() |
| 1914 | << "Read only mode set. Unable to" |
| 1915 | " open file '" << name << "' in RW mode, " |
| 1916 | << "trying RO mode"; |
| 1917 | } else { |
| 1918 | ut_ad(access_type == OS_FILE_READ_WRITE); |
| 1919 | access = GENERIC_READ | GENERIC_WRITE; |
| 1920 | } |
| 1921 | |
| 1922 | if (fil_system.is_write_through()) |
| 1923 | attributes |= FILE_FLAG_WRITE_THROUGH; |
| 1924 | if (!fil_system.is_buffered()) |
| 1925 | attributes |= FILE_FLAG_NO_BUFFERING; |
| 1926 | |
| 1927 | for (;;) { |
| 1928 | /* Use default security attributes and no template file. */ |
| 1929 | |
| 1930 | file = CreateFile( |
| 1931 | (LPCTSTR) name, access, |
| 1932 | FILE_SHARE_READ | FILE_SHARE_DELETE, |
| 1933 | my_win_file_secattr(), create_flag, attributes, NULL); |
| 1934 | |
| 1935 | if (file != INVALID_HANDLE_VALUE) { |
| 1936 | *success = true; |
| 1937 | break; |
| 1938 | } |
| 1939 | |
| 1940 | if (!os_file_handle_error_no_exit(name, |
| 1941 | create_flag == CREATE_NEW |
| 1942 | ? "create" : "open", |
| 1943 | false)) { |
| 1944 | break; |
| 1945 | } |
| 1946 | } |
| 1947 | |
| 1948 | return(file); |
| 1949 | } |
| 1950 | |
| 1951 | bool os_file_create_directory(const char *pathname, bool fail_if_exists) |
| 1952 | noexcept |
| 1953 | { |
| 1954 | BOOL rcode; |
| 1955 | |
| 1956 | rcode = CreateDirectory((LPCTSTR) pathname, NULL); |
| 1957 | if (!(rcode != 0 |
| 1958 | || (GetLastError() == ERROR_ALREADY_EXISTS |
| 1959 | && !fail_if_exists))) { |
| 1960 | |
| 1961 | os_file_handle_error_no_exit( |
| 1962 | pathname, "CreateDirectory", false); |
| 1963 | |
| 1964 | return(false); |
| 1965 | } |
| 1966 | |
| 1967 | return(true); |
| 1968 | } |
| 1969 | |
| 1970 | /** Get disk sector size for a file. */ |
| 1971 | static size_t get_sector_size(HANDLE file) |
| 1972 | { |
| 1973 | FILE_STORAGE_INFO fsi; |
| 1974 | ULONG s= 4096; |
| 1975 | if (GetFileInformationByHandleEx(file, FileStorageInfo, &fsi, sizeof fsi)) |
| 1976 | { |
| 1977 | s= fsi.PhysicalBytesPerSectorForPerformance; |
| 1978 | if (s > 4096 || s < 64 || !ut_is_2pow(s)) |
| 1979 | return 4096; |
| 1980 | } |
| 1981 | return s; |
| 1982 | } |
| 1983 | |
| 1984 | /** NOTE! Use the corresponding macro os_file_create(), not directly |
| 1985 | this function! |
| 1986 | Opens an existing file or creates a new. |
| 1987 | @param[in] name name of the file or path as a null-terminated |
| 1988 | string |
| 1989 | @param[in] create_mode create mode |
| 1990 | @param[in] type OS_DATA_FILE or OS_LOG_FILE |
| 1991 | @param[in] success true if succeeded |
| 1992 | @return handle to the file, not defined if error, error number |
| 1993 | can be retrieved with os_file_get_last_error */ |
| 1994 | pfs_os_file_t |
| 1995 | os_file_create_func( |
| 1996 | const char* name, |
| 1997 | os_file_create_t create_mode, |
| 1998 | ulint type, |
| 1999 | bool read_only, |
| 2000 | bool* success) noexcept |
| 2001 | { |
| 2002 | os_file_t file; |
| 2003 | |
| 2004 | *success = false; |
| 2005 | |
| 2006 | DBUG_EXECUTE_IF( |
| 2007 | "ib_create_table_fail_disk_full", |
| 2008 | *success = false; |
| 2009 | SetLastError(ERROR_DISK_FULL); |
| 2010 | return(OS_FILE_CLOSED); |
| 2011 | ); |
| 2012 | |
| 2013 | DWORD create_flag = OPEN_EXISTING; |
| 2014 | DWORD share_mode = read_only |
| 2015 | ? FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE |
| 2016 | : FILE_SHARE_READ | FILE_SHARE_DELETE; |
| 2017 | |
| 2018 | switch (create_mode) { |
| 2019 | case OS_FILE_OPEN_RAW: |
| 2020 | ut_a(!read_only); |
| 2021 | /* On Windows Physical devices require admin privileges and |
| 2022 | have to have the write-share mode set. See the remarks |
| 2023 | section for the CreateFile() function documentation in MSDN. */ |
| 2024 | |
| 2025 | share_mode |= FILE_SHARE_WRITE; |
| 2026 | break; |
| 2027 | case OS_FILE_CREATE_SILENT: |
| 2028 | case OS_FILE_CREATE: |
| 2029 | create_flag = CREATE_NEW; |
| 2030 | break; |
| 2031 | default: |
| 2032 | ut_ad(create_mode == OS_FILE_OPEN |
| 2033 | || create_mode == OS_FILE_OPEN_SILENT |
| 2034 | || create_mode == OS_FILE_OPEN_RETRY_SILENT |
| 2035 | || create_mode == OS_FILE_OPEN_RETRY); |
| 2036 | break; |
| 2037 | } |
| 2038 | |
| 2039 | DWORD attributes= FILE_FLAG_OVERLAPPED; |
| 2040 | |
| 2041 | if (type == OS_LOG_FILE) { |
| 2042 | if (!log_sys.is_opened() && !log_sys.log_buffered) { |
| 2043 | attributes|= FILE_FLAG_NO_BUFFERING; |
| 2044 | } |
| 2045 | if (log_sys.log_write_through) |
| 2046 | attributes|= FILE_FLAG_WRITE_THROUGH; |
| 2047 | } else { |
| 2048 | if (type == OS_DATA_FILE && !fil_system.is_buffered()) |
| 2049 | attributes|= FILE_FLAG_NO_BUFFERING; |
| 2050 | if (fil_system.is_write_through()) |
| 2051 | attributes|= FILE_FLAG_WRITE_THROUGH; |
| 2052 | } |
| 2053 | |
| 2054 | DWORD access = read_only ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE; |
| 2055 | |
| 2056 | for (;;) { |
| 2057 | const char *operation; |
| 2058 | |
| 2059 | /* Use default security attributes and no template file. */ |
| 2060 | file = CreateFile( |
| 2061 | name, access, share_mode, my_win_file_secattr(), |
| 2062 | create_flag, attributes, NULL); |
| 2063 | |
| 2064 | *success = file != INVALID_HANDLE_VALUE; |
| 2065 | |
| 2066 | if (*success && type == OS_LOG_FILE) { |
| 2067 | uint32_t s = uint32_t(get_sector_size(file)); |
| 2068 | log_sys.set_block_size(s); |
| 2069 | if (attributes & FILE_FLAG_NO_BUFFERING) { |
| 2070 | if (os_file_get_size(file) % s) { |
| 2071 | attributes &= ~FILE_FLAG_NO_BUFFERING; |
| 2072 | create_flag = OPEN_ALWAYS; |
| 2073 | CloseHandle(file); |
| 2074 | continue; |
| 2075 | } |
| 2076 | log_sys.log_buffered = false; |
| 2077 | } |
| 2078 | } |
| 2079 | |
| 2080 | if (*success) { |
| 2081 | break; |
| 2082 | } |
| 2083 | |
| 2084 | operation = create_flag == CREATE_NEW ? "create" : "open"; |
| 2085 | |
| 2086 | if (!os_file_handle_error_no_exit(name, operation, |
| 2087 | create_mode |
| 2088 | & OS_FILE_ON_ERROR_SILENT)) { |
| 2089 | break; |
| 2090 | } |
| 2091 | } |
| 2092 | |
| 2093 | if (*success && (attributes & FILE_FLAG_OVERLAPPED) && srv_thread_pool) { |
| 2094 | srv_thread_pool->bind(file); |
| 2095 | } |
| 2096 | return(file); |
| 2097 | } |
| 2098 | |
| 2099 | /** NOTE! Use the corresponding macro os_file_create_simple_no_error_handling(), |
| 2100 | not directly this function! |
| 2101 | A simple function to open or create a file. |
| 2102 | @param[in] name name of the file or path as a null-terminated |
| 2103 | string |
| 2104 | @param[in] create_mode create mode |
| 2105 | @param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or |
| 2106 | OS_FILE_READ_ALLOW_DELETE; the last option is |
| 2107 | used by a backup program reading the file |
| 2108 | @param[out] success true if succeeded |
| 2109 | @return own: handle to the file, not defined if error, error number |
| 2110 | can be retrieved with os_file_get_last_error */ |
| 2111 | |
| 2112 | pfs_os_file_t |
| 2113 | os_file_create_simple_no_error_handling_func( |
| 2114 | const char* name, |
| 2115 | os_file_create_t create_mode, |
| 2116 | ulint access_type, |
| 2117 | bool read_only, |
| 2118 | bool* success) noexcept |
| 2119 | { |
| 2120 | os_file_t file; |
| 2121 | |
| 2122 | DWORD access = GENERIC_READ; |
| 2123 | DWORD create_flag = OPEN_EXISTING; |
| 2124 | DWORD attributes = 0; |
| 2125 | DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_DELETE; |
| 2126 | |
| 2127 | ut_a(name); |
| 2128 | |
| 2129 | if (read_only) { |
| 2130 | share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE |
| 2131 | | FILE_SHARE_DELETE; |
| 2132 | } else { |
| 2133 | if (create_mode == OS_FILE_CREATE) { |
| 2134 | create_flag = CREATE_NEW; |
| 2135 | } else { |
| 2136 | ut_ad(create_mode == OS_FILE_OPEN); |
| 2137 | } |
| 2138 | |
| 2139 | switch (access_type) { |
| 2140 | case OS_FILE_READ_ONLY: break; |
| 2141 | case OS_FILE_READ_WRITE: |
| 2142 | access = GENERIC_READ | GENERIC_WRITE; |
| 2143 | break; |
| 2144 | default: |
| 2145 | ut_ad(access_type == OS_FILE_READ_ALLOW_DELETE); |
| 2146 | /* A backup program has to give mariadbd the maximum |
| 2147 | freedom to do what it likes with the file */ |
| 2148 | share_mode |= FILE_SHARE_DELETE | FILE_SHARE_WRITE |
| 2149 | | FILE_SHARE_READ; |
| 2150 | } |
| 2151 | } |
| 2152 | |
| 2153 | file = CreateFile((LPCTSTR) name, |
| 2154 | access, |
| 2155 | share_mode, |
| 2156 | my_win_file_secattr(), |
| 2157 | create_flag, |
| 2158 | attributes, |
| 2159 | NULL); // No template file |
| 2160 | |
| 2161 | *success = (file != INVALID_HANDLE_VALUE); |
| 2162 | |
| 2163 | return(file); |
| 2164 | } |
| 2165 | |
| 2166 | /** Deletes a file if it exists. The file has to be closed before calling this. |
| 2167 | @param[in] name file path as a null-terminated string |
| 2168 | @param[out] exist indicate if file pre-exist |
| 2169 | @return true if success */ |
| 2170 | bool |
| 2171 | os_file_delete_if_exists_func( |
| 2172 | const char* name, |
| 2173 | bool* exist) |
| 2174 | { |
| 2175 | ulint count = 0; |
| 2176 | |
| 2177 | if (exist != NULL) { |
| 2178 | *exist = true; |
| 2179 | } |
| 2180 | |
| 2181 | for (;;) { |
| 2182 | /* In Windows, deleting an .ibd file may fail if |
| 2183 | the file is being accessed by an external program, |
| 2184 | such as a backup tool. */ |
| 2185 | |
| 2186 | bool ret = DeleteFile((LPCTSTR) name); |
| 2187 | |
| 2188 | if (ret) { |
| 2189 | return(true); |
| 2190 | } |
| 2191 | |
| 2192 | switch (GetLastError()) { |
| 2193 | case ERROR_FILE_NOT_FOUND: |
| 2194 | case ERROR_PATH_NOT_FOUND: |
| 2195 | /* the file does not exist, this not an error */ |
| 2196 | if (exist != NULL) { |
| 2197 | *exist = false; |
| 2198 | } |
| 2199 | /* fall through */ |
| 2200 | case ERROR_ACCESS_DENIED: |
| 2201 | return(true); |
| 2202 | } |
| 2203 | |
| 2204 | ++count; |
| 2205 | |
| 2206 | if (count > 100 && 0 == (count % 10)) { |
| 2207 | |
| 2208 | /* Print error information */ |
| 2209 | os_file_get_last_error(true); |
| 2210 | |
| 2211 | ib::warn() << "Delete of file '" << name << "' failed."; |
| 2212 | } |
| 2213 | |
| 2214 | std::this_thread::sleep_for(std::chrono::seconds(1)); |
| 2215 | |
| 2216 | if (count > 2000) { |
| 2217 | |
| 2218 | return(false); |
| 2219 | } |
| 2220 | } |
| 2221 | } |
| 2222 | |
| 2223 | /** Deletes a file. The file has to be closed before calling this. |
| 2224 | @param[in] name File path as NUL terminated string |
| 2225 | @return true if success */ |
| 2226 | bool |
| 2227 | os_file_delete_func( |
| 2228 | const char* name) |
| 2229 | { |
| 2230 | ulint count = 0; |
| 2231 | |
| 2232 | for (;;) { |
| 2233 | /* In Windows, deleting an .ibd file may fail if |
| 2234 | the file is being accessed by an external program, |
| 2235 | such as a backup tool. */ |
| 2236 | |
| 2237 | BOOL ret = DeleteFile((LPCTSTR) name); |
| 2238 | |
| 2239 | if (ret) { |
| 2240 | return(true); |
| 2241 | } |
| 2242 | |
| 2243 | if (GetLastError() == ERROR_FILE_NOT_FOUND) { |
| 2244 | /* If the file does not exist, we classify this as |
| 2245 | a 'mild' error and return */ |
| 2246 | |
| 2247 | return(false); |
| 2248 | } |
| 2249 | |
| 2250 | ++count; |
| 2251 | |
| 2252 | if (count > 100 && 0 == (count % 10)) { |
| 2253 | |
| 2254 | /* print error information */ |
| 2255 | os_file_get_last_error(true); |
| 2256 | |
| 2257 | ib::warn() |
| 2258 | << "Cannot delete file '" << name << "'. Is " |
| 2259 | << "another program accessing it?"; |
| 2260 | } |
| 2261 | |
| 2262 | std::this_thread::sleep_for(std::chrono::seconds(1)); |
| 2263 | |
| 2264 | if (count > 2000) { |
| 2265 | |
| 2266 | return(false); |
| 2267 | } |
| 2268 | } |
| 2269 | |
| 2270 | ut_error; |
| 2271 | return(false); |
| 2272 | } |
| 2273 | |
| 2274 | /** NOTE! Use the corresponding macro os_file_rename(), not directly this |
| 2275 | function! |
| 2276 | Renames a file (can also move it to another directory). It is safest that the |
| 2277 | file is closed before calling this function. |
| 2278 | @param[in] oldpath old file path as a null-terminated string |
| 2279 | @param[in] newpath new file path |
| 2280 | @return true if success */ |
| 2281 | bool |
| 2282 | os_file_rename_func( |
| 2283 | const char* oldpath, |
| 2284 | const char* newpath) |
| 2285 | { |
| 2286 | #ifdef UNIV_DEBUG |
| 2287 | os_file_type_t type; |
| 2288 | bool exists; |
| 2289 | |
| 2290 | /* New path must not exist. */ |
| 2291 | ut_ad(os_file_status(newpath, &exists, &type)); |
| 2292 | ut_ad(!exists); |
| 2293 | |
| 2294 | /* Old path must exist. */ |
| 2295 | ut_ad(os_file_status(oldpath, &exists, &type)); |
| 2296 | ut_ad(exists); |
| 2297 | #endif /* UNIV_DEBUG */ |
| 2298 | |
| 2299 | for (int retry= 50;; retry--){ |
| 2300 | if (MoveFileEx(oldpath, newpath, MOVEFILE_REPLACE_EXISTING)) |
| 2301 | return true; |
| 2302 | |
| 2303 | if (!retry) |
| 2304 | break; |
| 2305 | |
| 2306 | if (GetLastError() != ERROR_SHARING_VIOLATION) |
| 2307 | break; |
| 2308 | |
| 2309 | // oldpath was opened by someone else (antivirus?) |
| 2310 | //without FILE_SHARE_DELETE flag. Retry operation |
| 2311 | |
| 2312 | Sleep(10); |
| 2313 | } |
| 2314 | |
| 2315 | os_file_handle_rename_error(oldpath, newpath); |
| 2316 | return(false); |
| 2317 | } |
| 2318 | |
| 2319 | /** NOTE! Use the corresponding macro os_file_close(), not directly |
| 2320 | this function! |
| 2321 | Closes a file handle. In case of error, error number can be retrieved with |
| 2322 | os_file_get_last_error. |
| 2323 | @param[in,own] file Handle to a file |
| 2324 | @return true if success */ |
| 2325 | bool os_file_close_func(os_file_t file) |
| 2326 | { |
| 2327 | ut_ad(file); |
| 2328 | if (!CloseHandle(file)) |
| 2329 | { |
| 2330 | os_file_handle_error("close"); |
| 2331 | return false; |
| 2332 | } |
| 2333 | |
| 2334 | if(srv_thread_pool) |
| 2335 | srv_thread_pool->unbind(file); |
| 2336 | return true; |
| 2337 | } |
| 2338 | |
| 2339 | os_offset_t os_file_get_size(os_file_t file) noexcept |
| 2340 | { |
| 2341 | LARGE_INTEGER li; |
| 2342 | if (GetFileSizeEx(file, &li)) |
| 2343 | return li.QuadPart; |
| 2344 | return ((os_offset_t) -1); |
| 2345 | } |
| 2346 | |
| 2347 | os_file_size_t os_file_get_size(const char *filename) noexcept |
| 2348 | { |
| 2349 | struct __stat64 s; |
| 2350 | os_file_size_t file_size; |
| 2351 | |
| 2352 | int ret = _stat64(filename, &s); |
| 2353 | |
| 2354 | if (ret == 0) { |
| 2355 | |
| 2356 | file_size.m_total_size = s.st_size; |
| 2357 | |
| 2358 | DWORD low_size; |
| 2359 | DWORD high_size; |
| 2360 | |
| 2361 | low_size = GetCompressedFileSize(filename, &high_size); |
| 2362 | |
| 2363 | if (low_size != INVALID_FILE_SIZE) { |
| 2364 | |
| 2365 | file_size.m_alloc_size = high_size; |
| 2366 | file_size.m_alloc_size <<= 32; |
| 2367 | file_size.m_alloc_size |= low_size; |
| 2368 | |
| 2369 | } else { |
| 2370 | ib::error() |
| 2371 | << "GetCompressedFileSize(" |
| 2372 | << filename << ", ..) failed."; |
| 2373 | |
| 2374 | file_size.m_alloc_size = (os_offset_t) -1; |
| 2375 | } |
| 2376 | } else { |
| 2377 | file_size.m_total_size = ~0; |
| 2378 | file_size.m_alloc_size = (os_offset_t) ret; |
| 2379 | } |
| 2380 | |
| 2381 | return(file_size); |
| 2382 | } |
| 2383 | |
| 2384 | /** This function returns information about the specified file |
| 2385 | @param[in] path pathname of the file |
| 2386 | @param[out] stat_info information of a file in a directory |
| 2387 | @param[in,out] statinfo information of a file in a directory |
| 2388 | @param[in] check_rw_perm for testing whether the file can be opened |
| 2389 | in RW mode |
| 2390 | @param[in] read_only true if the file is opened in read-only mode |
| 2391 | @return DB_SUCCESS if all OK */ |
| 2392 | static |
| 2393 | dberr_t |
| 2394 | os_file_get_status_win32( |
| 2395 | const char* path, |
| 2396 | os_file_stat_t* stat_info, |
| 2397 | struct _stat64* statinfo, |
| 2398 | bool check_rw_perm, |
| 2399 | bool read_only) |
| 2400 | { |
| 2401 | int ret = _stat64(path, statinfo); |
| 2402 | |
| 2403 | if (ret && (errno == ENOENT || errno == ENOTDIR |
| 2404 | || errno == ENAMETOOLONG)) { |
| 2405 | /* file does not exist */ |
| 2406 | |
| 2407 | return(DB_NOT_FOUND); |
| 2408 | |
| 2409 | } else if (ret) { |
| 2410 | /* file exists, but stat call failed */ |
| 2411 | |
| 2412 | os_file_handle_error_no_exit(path, "STAT", false); |
| 2413 | |
| 2414 | return(DB_FAIL); |
| 2415 | |
| 2416 | } else if (_S_IFDIR & statinfo->st_mode) { |
| 2417 | |
| 2418 | stat_info->type = OS_FILE_TYPE_DIR; |
| 2419 | |
| 2420 | } else if (_S_IFREG & statinfo->st_mode) { |
| 2421 | |
| 2422 | DWORD access = GENERIC_READ; |
| 2423 | |
| 2424 | if (!read_only) { |
| 2425 | access |= GENERIC_WRITE; |
| 2426 | } |
| 2427 | |
| 2428 | stat_info->type = OS_FILE_TYPE_FILE; |
| 2429 | |
| 2430 | /* Check if we can open it in read-only mode. */ |
| 2431 | |
| 2432 | if (check_rw_perm) { |
| 2433 | HANDLE fh; |
| 2434 | |
| 2435 | fh = CreateFile( |
| 2436 | (LPCTSTR) path, // File to open |
| 2437 | access, |
| 2438 | FILE_SHARE_READ | FILE_SHARE_WRITE |
| 2439 | | FILE_SHARE_DELETE, // Full sharing |
| 2440 | my_win_file_secattr(), |
| 2441 | OPEN_EXISTING, // Existing file only |
| 2442 | FILE_ATTRIBUTE_NORMAL, // Normal file |
| 2443 | NULL); // No attr. template |
| 2444 | |
| 2445 | if (fh == INVALID_HANDLE_VALUE) { |
| 2446 | stat_info->rw_perm = false; |
| 2447 | } else { |
| 2448 | stat_info->rw_perm = true; |
| 2449 | CloseHandle(fh); |
| 2450 | } |
| 2451 | } |
| 2452 | } else { |
| 2453 | stat_info->type = OS_FILE_TYPE_UNKNOWN; |
| 2454 | } |
| 2455 | |
| 2456 | return(DB_SUCCESS); |
| 2457 | } |
| 2458 | |
| 2459 | /** |
| 2460 | Sets a sparse flag on Windows file. |
| 2461 | @param[in] file file handle |
| 2462 | @return true on success, false on error |
| 2463 | */ |
| 2464 | #include <versionhelpers.h> |
| 2465 | bool os_file_set_sparse_win32(os_file_t file, bool is_sparse) noexcept |
| 2466 | { |
| 2467 | if (!is_sparse && !IsWindows8OrGreater()) { |
| 2468 | /* Cannot unset sparse flag on older Windows. |
| 2469 | Until Windows8 it is documented to produce unpredictable results, |
| 2470 | if there are unallocated ranges in file.*/ |
| 2471 | return false; |
| 2472 | } |
| 2473 | DWORD temp; |
| 2474 | FILE_SET_SPARSE_BUFFER sparse_buffer; |
| 2475 | sparse_buffer.SetSparse = is_sparse; |
| 2476 | return os_win32_device_io_control(file, |
| 2477 | FSCTL_SET_SPARSE, &sparse_buffer, sizeof(sparse_buffer), 0, 0,&temp); |
| 2478 | } |
| 2479 | |
| 2480 | bool os_file_set_size(const char *pathname, os_file_t file, os_offset_t size) |
| 2481 | noexcept |
| 2482 | { |
| 2483 | LARGE_INTEGER length; |
| 2484 | |
| 2485 | length.QuadPart = size; |
| 2486 | |
| 2487 | BOOL success = SetFilePointerEx(file, length, NULL, FILE_BEGIN); |
| 2488 | |
| 2489 | if (!success) { |
| 2490 | os_file_handle_error_no_exit( |
| 2491 | pathname, "SetFilePointerEx", false); |
| 2492 | } else { |
| 2493 | success = SetEndOfFile(file); |
| 2494 | if (!success) { |
| 2495 | os_file_handle_error_no_exit( |
| 2496 | pathname, "SetEndOfFile", false); |
| 2497 | } |
| 2498 | } |
| 2499 | return(success); |
| 2500 | } |
| 2501 | |
| 2502 | bool os_file_set_eof(FILE *file) noexcept |
| 2503 | { |
| 2504 | HANDLE h = (HANDLE) _get_osfhandle(fileno(file)); |
| 2505 | |
| 2506 | return(SetEndOfFile(h)); |
| 2507 | } |
| 2508 | |
| 2509 | #endif /* !_WIN32*/ |
| 2510 | |
| 2511 | /** Does a synchronous read or write depending upon the type specified |
| 2512 | In case of partial reads/writes the function tries |
| 2513 | NUM_RETRIES_ON_PARTIAL_IO times to read/write the complete data. |
| 2514 | @param[in] type, IO flags |
| 2515 | @param[in] file handle to an open file |
| 2516 | @param[out] buf buffer where to read |
| 2517 | @param[in] offset file offset from the start where to read |
| 2518 | @param[in] n number of bytes to read, starting from offset |
| 2519 | @param[out] err DB_SUCCESS or error code |
| 2520 | @return number of bytes read/written, -1 if error */ |
| 2521 | static MY_ATTRIBUTEcxx . . $ `storage/innobase/include/univ.i:162:11`!((warn_unused_result)) |
| 2522 | ssize_t |
| 2523 | os_file_iocxx . . $ os_file_io(91f2e5d64909acb2).( |
| 2524 | const IORequestcxx . . $ IORequest#&in_type, |
| 2525 | os_file_tcxx . . $ os_file_t# file, |
| 2526 | void* buf, |
| 2527 | ulintcxx . . $ ulint# n, |
| 2528 | os_offset_tcxx . . $ os_offset_t# offset, |
| 2529 | dberr_tcxx . . $ dberr_t#* err) |
| 2530 | { |
| 2531 | ssize_t original_n = ssize_t(n); |
| 2532 | IORequestcxx . . $ IORequest# type = in_type; |
| 2533 | ssize_t bytes_returned = 0; |
| 2534 | |
| 2535 | SyncFileIOcxx . . $ SyncFileIO# sync_file_iocxx . . $ SyncFileIO#SyncFileIO(c657295257626a91).(file, buf, n, offset); |
| 2536 | |
| 2537 | for (ulintcxx . . $ ulint# i = 0; i < NUM_RETRIES_ON_PARTIAL_IOcxx . . $ NUM_RETRIES_ON_PARTIAL_IO.; ++i) { |
| 2538 | |
| 2539 | ssize_t n_bytes = sync_file_io.executecxx . . $ SyncFileIO#execute(c1483fbf63a8ac4e).(type); |
| 2540 | |
| 2541 | /* Check for a hard error. Not much we can do now. */ |
| 2542 | if (n_bytes < 0) { |
| 2543 | |
| 2544 | break; |
| 2545 | |
| 2546 | } else if (n_bytes + bytes_returned == ssize_t(n)) { |
| 2547 | |
| 2548 | bytes_returned += n_bytes; |
| 2549 | |
| 2550 | *err = type.maybe_punch_holecxx . . $ IORequest#maybe_punch_hole(5ca34a1d2d926fdf).(offset, n); |
| 2551 | |
| 2552 | return(original_n); |
| 2553 | } |
| 2554 | |
| 2555 | /* Handle partial read/write. */ |
| 2556 | |
| 2557 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(ulint(n_bytes + bytes_returned) < n); |
| 2558 | |
| 2559 | bytes_returned += n_bytes; |
| 2560 | |
| 2561 | if (type.typecxx . . $ IORequest#type. != IORequestcxx . . $ IORequest#::READ_MAYBE_PARTIALcxx . . $ IORequest#READ_MAYBE_PARTIAL.) { |
| 2562 | sql_print_warningcxx . . $ sql_print_warning(326aeb464d16410c).("InnoDB: %zu bytes should have been" |
| 2563 | " %s at %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! " from %s," |
| 2564 | " but got only %zd." |
| 2565 | " Retrying.", |
| 2566 | n, type.is_readcxx . . $ IORequest#is_read(3482b152b9333168).() |
| 2567 | ? "read" : "written", offset, |
| 2568 | type.nodecxx . . $ IORequest#node. |
| 2569 | ? type.nodecxx . . $ IORequest#node.->namecxx . . $ fil_node_t#name. |
| 2570 | : "(unknown file)", bytes_returned); |
| 2571 | } |
| 2572 | |
| 2573 | /* Advance the offset and buffer by n_bytes */ |
| 2574 | sync_file_io.advancecxx . . $ SyncFileIO#advance(1624ee8275b10bda).(n_bytes); |
| 2575 | } |
| 2576 | |
| 2577 | *err = DB_IO_ERRORcxx . . $ DB_IO_ERROR.; |
| 2578 | |
| 2579 | if (type.typecxx . . $ IORequest#type. != IORequestcxx . . $ IORequest#::READ_MAYBE_PARTIALcxx . . $ IORequest#READ_MAYBE_PARTIAL.) { |
| 2580 | ibcxx . . $ ib/::warncxx . . $ ib/warn#() |
| 2581 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Retry attempts for " |
| 2582 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). (type.is_readcxx . . $ IORequest#is_read(3482b152b9333168).() ? "reading" : "writing") |
| 2583 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " partial data failed."; |
| 2584 | } |
| 2585 | |
| 2586 | return(bytes_returned); |
| 2587 | } |
| 2588 | |
| 2589 | /** Does a synchronous write operation in Posix. |
| 2590 | @param[in] type IO context |
| 2591 | @param[in] file handle to an open file |
| 2592 | @param[out] buf buffer from which to write |
| 2593 | @param[in] n number of bytes to write, starting from offset |
| 2594 | @param[in] offset file offset from the start where to write |
| 2595 | @param[out] err DB_SUCCESS or error code |
| 2596 | @return number of bytes written |
| 2597 | @retval -1 on error */ |
| 2598 | static MY_ATTRIBUTEcxx . . $ `storage/innobase/include/univ.i:162:11`!((warn_unused_result)) |
| 2599 | ssize_t |
| 2600 | os_file_pwritecxx . . $ os_file_pwrite(aa366aa629549fd).( |
| 2601 | const IORequestcxx . . $ IORequest#& type, |
| 2602 | os_file_tcxx . . $ os_file_t# file, |
| 2603 | const bytecxx . . $ byte#* buf, |
| 2604 | ulintcxx . . $ ulint# n, |
| 2605 | os_offset_tcxx . . $ os_offset_t# offset, |
| 2606 | dberr_tcxx . . $ dberr_t#* err) |
| 2607 | { |
| 2608 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(type.is_write()); |
| 2609 | |
| 2610 | ++cxx . . $ Atomic_counter#operator++(5f357b03ed472e5e).os_n_file_writescxx . . $ os_n_file_writes.; |
| 2611 | |
| 2612 | const bool monitor = MONITOR_IS_ONcxx . . $ `storage/innobase/include/srv0mon.h:431:9`!(MONITOR_OS_PENDING_WRITES); |
| 2613 | MONITOR_ATOMIC_INC_LOWcxx . . $ `storage/innobase/include/srv0mon.h:524:9`!(MONITOR_OS_PENDING_WRITES, monitor); |
| 2614 | ssize_t n_bytes = os_file_iocxx . . $ os_file_io(91f2e5d64909acb2).(type, file, const_cast<bytecxx . . $ byte#*>(buf), |
| 2615 | n, offset, err); |
| 2616 | MONITOR_ATOMIC_DEC_LOWcxx . . $ `storage/innobase/include/srv0mon.h:541:9`!(MONITOR_OS_PENDING_WRITES, monitor); |
| 2617 | |
| 2618 | return(n_bytes); |
| 2619 | } |
| 2620 | |
| 2621 | /** NOTE! Use the corresponding macro os_file_write(), not directly |
| 2622 | Requests a synchronous write operation. |
| 2623 | @param[in] type IO flags |
| 2624 | @param[in] file handle to an open file |
| 2625 | @param[out] buf buffer from which to write |
| 2626 | @param[in] offset file offset from the start where to read |
| 2627 | @param[in] n number of bytes to read, starting from offset |
| 2628 | @return error code |
| 2629 | @retval DB_SUCCESS if the operation succeeded */ |
| 2630 | dberr_tcxx . . $ dberr_t# |
| 2631 | os_file_write_funccxx . . $ os_file_write_func(27b9ed7ec5c91f27).( |
| 2632 | const IORequestcxx . . $ IORequest#& type, |
| 2633 | const char* name, |
| 2634 | os_file_tcxx . . $ os_file_t# file, |
| 2635 | const void* buf, |
| 2636 | os_offset_tcxx . . $ os_offset_t# offset, |
| 2637 | ulintcxx . . $ ulint# n) |
| 2638 | { |
| 2639 | dberr_tcxx . . $ dberr_t# err; |
| 2640 | |
| 2641 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(n > 0); |
| 2642 | |
| 2643 | ssize_t n_bytes = os_file_pwritecxx . . $ os_file_pwrite(aa366aa629549fd).(type, file, (bytecxx . . $ byte#*)buf, n, offset, &err); |
| 2644 | |
| 2645 | if ((ulintcxx . . $ ulint#) n_bytes != n && !os_has_said_disk_fullcxx . . $ os_has_said_disk_full.) { |
| 2646 | |
| 2647 | ibcxx . . $ ib/::errorcxx . . $ ib/error#() |
| 2648 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Write to file " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). name <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " failed at offset " |
| 2649 | <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). offset <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). ", " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). n |
| 2650 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " bytes should have been written," |
| 2651 | " only " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). n_bytes <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " were written." |
| 2652 | " Operating system error number " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). IF_WINcxx . . $ `include/my_global.h:97:9`!(GetLastError(),errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "." |
| 2653 | " Check that your OS and file system" |
| 2654 | " support files of this size." |
| 2655 | " Check also that the disk is not full" |
| 2656 | " or a disk quota exceeded."; |
| 2657 | #ifndef _WIN32 |
| 2658 | if (strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 2659 | |
| 2660 | ibcxx . . $ ib/::errorcxx . . $ ib/error#() |
| 2661 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Error number " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! |
| 2662 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " means '" <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "'"; |
| 2663 | } |
| 2664 | |
| 2665 | ibcxx . . $ ib/::infocxx . . $ ib/info#() <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). OPERATING_SYSTEM_ERROR_MSGcxx . . $ OPERATING_SYSTEM_ERROR_MSG.; |
| 2666 | #endif |
| 2667 | os_has_said_disk_fullcxx . . $ os_has_said_disk_full. = true; |
| 2668 | } |
| 2669 | |
| 2670 | return(err); |
| 2671 | } |
| 2672 | |
| 2673 | /** Does a synchronous read operation in Posix. |
| 2674 | @param[in] type IO flags |
| 2675 | @param[in] file handle to an open file |
| 2676 | @param[out] buf buffer where to read |
| 2677 | @param[in] offset file offset from the start where to read |
| 2678 | @param[in] n number of bytes to read, starting from offset |
| 2679 | @param[out] err DB_SUCCESS or error code |
| 2680 | @return number of bytes read, -1 if error */ |
| 2681 | static MY_ATTRIBUTEcxx . . $ `storage/innobase/include/univ.i:162:11`!((warn_unused_result)) |
| 2682 | ssize_t |
| 2683 | os_file_preadcxx . . $ os_file_pread(91f2e5d64909acb2).( |
| 2684 | const IORequestcxx . . $ IORequest#& type, |
| 2685 | os_file_tcxx . . $ os_file_t# file, |
| 2686 | void* buf, |
| 2687 | ulintcxx . . $ ulint# n, |
| 2688 | os_offset_tcxx . . $ os_offset_t# offset, |
| 2689 | dberr_tcxx . . $ dberr_t#* err) |
| 2690 | { |
| 2691 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(type.is_read()); |
| 2692 | |
| 2693 | ++cxx . . $ Atomic_counter#operator++(5f357b03ed472e5e).os_n_file_readscxx . . $ os_n_file_reads.; |
| 2694 | |
| 2695 | const bool monitor = MONITOR_IS_ONcxx . . $ `storage/innobase/include/srv0mon.h:431:9`!(MONITOR_OS_PENDING_READS); |
| 2696 | MONITOR_ATOMIC_INC_LOWcxx . . $ `storage/innobase/include/srv0mon.h:524:9`!(MONITOR_OS_PENDING_READS, monitor); |
| 2697 | ssize_t n_bytes = os_file_iocxx . . $ os_file_io(91f2e5d64909acb2).(type, file, buf, n, offset, err); |
| 2698 | MONITOR_ATOMIC_DEC_LOWcxx . . $ `storage/innobase/include/srv0mon.h:541:9`!(MONITOR_OS_PENDING_READS, monitor); |
| 2699 | |
| 2700 | return(n_bytes); |
| 2701 | } |
| 2702 | |
| 2703 | /** Requests a synchronous positioned read operation. |
| 2704 | @return DB_SUCCESS if request was successful, false if fail |
| 2705 | @param[in] type IO flags |
| 2706 | @param[in] file handle to an open file |
| 2707 | @param[out] buf buffer where to read |
| 2708 | @param[in] offset file offset from the start where to read |
| 2709 | @param[in] n number of bytes to read, starting from offset |
| 2710 | @param[out] o number of bytes actually read |
| 2711 | @return DB_SUCCESS or error code */ |
| 2712 | dberr_tcxx . . $ dberr_t# |
| 2713 | os_file_read_funccxx . . $ os_file_read_func(8dd0cab60fa19858).( |
| 2714 | const IORequestcxx . . $ IORequest#& type, |
| 2715 | os_file_tcxx . . $ os_file_t# file, |
| 2716 | void* buf, |
| 2717 | os_offset_tcxx . . $ os_offset_t# offset, |
| 2718 | ulintcxx . . $ ulint# n, |
| 2719 | ulintcxx . . $ ulint#* o) noexcept |
| 2720 | { |
| 2721 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!type.node || type.node->handle == file); |
| 2722 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(n); |
| 2723 | |
| 2724 | os_bytes_read_since_printoutcxx . . $ os_bytes_read_since_printout.+= n; |
| 2725 | |
| 2726 | dberr_tcxx . . $ dberr_t# err; |
| 2727 | ssize_t n_bytes= os_file_preadcxx . . $ os_file_pread(91f2e5d64909acb2).(type, file, buf, n, offset, &err); |
| 2728 | |
| 2729 | if (o) |
| 2730 | *o= ulintcxx . . $ ulint#(n_bytes); |
| 2731 | |
| 2732 | if (ulintcxx . . $ ulint#(n_bytes) == n || err != DB_SUCCESScxx . . $ DB_SUCCESS.) |
| 2733 | return err; |
| 2734 | |
| 2735 | os_file_handle_error_no_exitcxx . . $ os_file_handle_error_no_exit(567fbfac950d45).(type.nodecxx . . $ IORequest#node. ? type.nodecxx . . $ IORequest#node.->namecxx . . $ fil_node_t#name. : nullptr, "read", |
| 2736 | false); |
| 2737 | sql_print_errorcxx . . $ sql_print_error(326aeb464d16410c).("InnoDB: Tried to read %zu bytes at offset %" PRIu64cxx . . $ `<external>/15933738808807975373/inttypes.h:105:10`! |
| 2738 | " of file %s, but was only able to read %zd", |
| 2739 | n, offset, type.nodecxx . . $ IORequest#node. ? type.nodecxx . . $ IORequest#node.->namecxx . . $ fil_node_t#name. : "(unknown)", |
| 2740 | n_bytes); |
| 2741 | |
| 2742 | return err ? err : DB_IO_ERRORcxx . . $ DB_IO_ERROR.; |
| 2743 | } |
| 2744 | |
| 2745 | /** Handle errors for file operations. |
| 2746 | @param[in] name name of a file or NULL |
| 2747 | @param[in] operation operation |
| 2748 | @param[in] should_abort whether to abort on an unknown error |
| 2749 | @param[in] on_error_silent whether to suppress reports of non-fatal errors |
| 2750 | @return true if we should retry the operation */ |
| 2751 | static MY_ATTRIBUTEcxx . . $ `storage/innobase/include/univ.i:162:11`!((warn_unused_result)) |
| 2752 | bool |
| 2753 | os_file_handle_error_cond_exitcxx . . $ os_file_handle_error_cond_exit(46800fedf44cd2c4).( |
| 2754 | const char* name, |
| 2755 | const char* operation, |
| 2756 | bool should_abort, |
| 2757 | bool on_error_silent) noexcept |
| 2758 | { |
| 2759 | ulintcxx . . $ ulint# err; |
| 2760 | |
| 2761 | err = os_file_get_last_errorcxx . . $ os_file_get_last_error(19c5c1b41feeabaf).(false, on_error_silent); |
| 2762 | |
| 2763 | switch (err) { |
| 2764 | case OS_FILE_DISK_FULLcxx . . $ OS_FILE_DISK_FULL.: |
| 2765 | /* We only print a warning about disk full once */ |
| 2766 | |
| 2767 | if (os_has_said_disk_fullcxx . . $ os_has_said_disk_full.) { |
| 2768 | |
| 2769 | return(false); |
| 2770 | } |
| 2771 | |
| 2772 | /* Disk full error is reported irrespective of the |
| 2773 | on_error_silent setting. */ |
| 2774 | |
| 2775 | if (name) { |
| 2776 | |
| 2777 | ibcxx . . $ ib/::errorcxx . . $ ib/error#() |
| 2778 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Encountered a problem with file '" |
| 2779 | <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). name <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "'"; |
| 2780 | } |
| 2781 | |
| 2782 | ibcxx . . $ ib/::errorcxx . . $ ib/error#() |
| 2783 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "Disk is full. Try to clean the disk to free space."; |
| 2784 | |
| 2785 | os_has_said_disk_fullcxx . . $ os_has_said_disk_full. = true; |
| 2786 | |
| 2787 | return(false); |
| 2788 | |
| 2789 | case OS_FILE_AIO_RESOURCES_RESERVEDcxx . . $ OS_FILE_AIO_RESOURCES_RESERVED.: |
| 2790 | case OS_FILE_AIO_INTERRUPTEDcxx . . $ OS_FILE_AIO_INTERRUPTED.: |
| 2791 | |
| 2792 | return(true); |
| 2793 | |
| 2794 | case OS_FILE_PATH_ERRORcxx . . $ OS_FILE_PATH_ERROR.: |
| 2795 | case OS_FILE_ALREADY_EXISTScxx . . $ OS_FILE_ALREADY_EXISTS.: |
| 2796 | case OS_FILE_ACCESS_VIOLATIONcxx . . $ OS_FILE_ACCESS_VIOLATION.: |
| 2797 | return(false); |
| 2798 | |
| 2799 | case OS_FILE_NOT_FOUNDcxx . . $ OS_FILE_NOT_FOUND.: |
| 2800 | if (!on_error_silent) { |
| 2801 | sql_print_errorcxx . . $ sql_print_error(326aeb464d16410c).("InnoDB: File %s was not found", name); |
| 2802 | } |
| 2803 | return false; |
| 2804 | |
| 2805 | case OS_FILE_SHARING_VIOLATIONcxx . . $ OS_FILE_SHARING_VIOLATION.: |
| 2806 | |
| 2807 | stdcxx . . $ std/::this_threadcxx . . $ std/this_thread/::sleep_forcxx . . $ std/this_thread/sleep_for(fb2140da9187dddf).(stdcxx . . $ std/::chronocxx . . $ std/chrono/::secondscxx . . $ std/chrono/seconds#(10)); |
| 2808 | return(true); |
| 2809 | |
| 2810 | case OS_FILE_OPERATION_ABORTEDcxx . . $ OS_FILE_OPERATION_ABORTED.: |
| 2811 | case OS_FILE_INSUFFICIENT_RESOURCEcxx . . $ OS_FILE_INSUFFICIENT_RESOURCE.: |
| 2812 | |
| 2813 | stdcxx . . $ std/::this_threadcxx . . $ std/this_thread/::sleep_forcxx . . $ std/this_thread/sleep_for(fb2140da9187dddf).(stdcxx . . $ std/::chronocxx . . $ std/chrono/::millisecondscxx . . $ std/chrono/milliseconds#(100)); |
| 2814 | return(true); |
| 2815 | |
| 2816 | default: |
| 2817 | |
| 2818 | /* If it is an operation that can crash on error then it |
| 2819 | is better to ignore on_error_silent and print an error message |
| 2820 | to the log. */ |
| 2821 | |
| 2822 | if (should_abort || !on_error_silent) { |
| 2823 | ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "File " |
| 2824 | <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). (name != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! ? name : "(unknown)") |
| 2825 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). ": '" <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). operation <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "'" |
| 2826 | " returned OS error " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). err <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "." |
| 2827 | <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). (should_abort |
| 2828 | ? " Cannot continue operation" : ""); |
| 2829 | } |
| 2830 | |
| 2831 | if (should_abort) { |
| 2832 | abortcxx . . $ abort(15d318a79ddce9e0).(); |
| 2833 | } |
| 2834 | } |
| 2835 | |
| 2836 | return(false); |
| 2837 | } |
| 2838 | |
| 2839 | /** Check if the file system supports sparse files. |
| 2840 | @param fh file handle |
| 2841 | @return true if the file system supports sparse files */ |
| 2842 | static bool os_is_sparse_file_supportedcxx . . $ os_is_sparse_file_supported(109becb148f4ca36).(os_file_tcxx . . $ os_file_t# fh) noexcept |
| 2843 | { |
| 2844 | #ifdef _WIN32 |
| 2845 | FILE_ATTRIBUTE_TAG_INFO info; |
| 2846 | if (GetFileInformationByHandleEx(fh, FileAttributeTagInfo, |
| 2847 | &info, (DWORD)sizeof(info))) { |
| 2848 | if (info.FileAttributes != INVALID_FILE_ATTRIBUTES) { |
| 2849 | return (info.FileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) != 0; |
| 2850 | } |
| 2851 | } |
| 2852 | return false; |
| 2853 | #else |
| 2854 | /* We don't know the FS block size, use the sector size. The FS |
| 2855 | will do the magic. */ |
| 2856 | return DB_SUCCESScxx . . $ DB_SUCCESS. == os_file_punch_hole_posixcxx . . $ os_file_punch_hole_posix(5135d13d1110631c).(fh, 0, srv_page_sizecxx . . $ srv_page_size.); |
| 2857 | #endif /* _WIN32 */ |
| 2858 | } |
| 2859 | |
| 2860 | /** Truncate a file to a specified size in bytes. |
| 2861 | @param[in] pathname file path |
| 2862 | @param[in] file file to be truncated |
| 2863 | @param[in] size size preserved in bytes |
| 2864 | @param[in] allow_shrink whether to allow the file to become smaller |
| 2865 | @return true if success */ |
| 2866 | bool |
| 2867 | os_file_truncatecxx . . $ os_file_truncate(c5e330475387994b).( |
| 2868 | const char* pathname, |
| 2869 | os_file_tcxx . . $ os_file_t# file, |
| 2870 | os_offset_tcxx . . $ os_offset_t# size, |
| 2871 | bool allow_shrink) noexcept |
| 2872 | { |
| 2873 | if (!allow_shrink) { |
| 2874 | /* Do nothing if the size preserved is larger than or |
| 2875 | equal to the current size of file */ |
| 2876 | os_offset_tcxx . . $ os_offset_t# size_bytes = os_file_get_sizecxx . . $ os_file_get_size(a516d6ace67a1470).(file); |
| 2877 | |
| 2878 | if (size >= size_bytes) { |
| 2879 | return(true); |
| 2880 | } |
| 2881 | } |
| 2882 | |
| 2883 | #ifdef _WIN32 |
| 2884 | return os_file_set_size(pathname, file, size); |
| 2885 | #else /* _WIN32 */ |
| 2886 | return(os_file_truncate_posixcxx . . $ os_file_truncate_posix(4efae755e34f93d9).(pathname, file, size)); |
| 2887 | #endif /* _WIN32 */ |
| 2888 | } |
| 2889 | |
| 2890 | /** Check the existence and type of the given file. |
| 2891 | @param[in] path path name of file |
| 2892 | @param[out] exists true if the file exists |
| 2893 | @param[out] type Type of the file, if it exists |
| 2894 | @return true if call succeeded */ |
| 2895 | bool |
| 2896 | os_file_statuscxx . . $ os_file_status(b6307a5813339b46).( |
| 2897 | const char* path, |
| 2898 | bool* exists, |
| 2899 | os_file_type_tcxx . . $ os_file_type_t#* type) noexcept |
| 2900 | { |
| 2901 | #ifdef _WIN32 |
| 2902 | return(os_file_status_win32(path, exists, type)); |
| 2903 | #else |
| 2904 | return(os_file_status_posixcxx . . $ os_file_status_posix(b6307a5813339b46).(path, exists, type)); |
| 2905 | #endif /* _WIN32 */ |
| 2906 | } |
| 2907 | |
| 2908 | /** Free storage space associated with a section of the file. |
| 2909 | @param[in] fh Open file handle |
| 2910 | @param[in] off Starting offset (SEEK_SET) |
| 2911 | @param[in] len Size of the hole |
| 2912 | @return DB_SUCCESS or error code */ |
| 2913 | dberr_tcxx . . $ dberr_t# |
| 2914 | os_file_punch_holecxx . . $ os_file_punch_hole(f4234bfafe1749a0).( |
| 2915 | os_file_tcxx . . $ os_file_t# fh, |
| 2916 | os_offset_tcxx . . $ os_offset_t# off, |
| 2917 | os_offset_tcxx . . $ os_offset_t# len) noexcept |
| 2918 | { |
| 2919 | #ifdef _WIN32 |
| 2920 | return os_file_punch_hole_win32(fh, off, len); |
| 2921 | #else |
| 2922 | return os_file_punch_hole_posixcxx . . $ os_file_punch_hole_posix(5135d13d1110631c).(fh, off, len); |
| 2923 | #endif /* _WIN32 */ |
| 2924 | } |
| 2925 | |
| 2926 | /** Free storage space associated with a section of the file. |
| 2927 | @param off byte offset from the start (SEEK_SET) |
| 2928 | @param len size of the hole in bytes |
| 2929 | @return DB_SUCCESS or error code */ |
| 2930 | dberr_tcxx . . $ dberr_t# IORequestcxx . . $ IORequest#::punch_holecxx . . $ IORequest#punch_hole(9d753e731e623157).(os_offset_tcxx . . $ os_offset_t# off, ulintcxx . . $ ulint# len) const noexcept |
| 2931 | { |
| 2932 | ulintcxx . . $ ulint# trim_len = bpagecxx . . $ IORequest#bpage. ? bpagecxx . . $ IORequest#bpage.->physical_sizecxx . . $ buf_page_t#physical_size(c9b1e749b64d5edc).() - len : 0; |
| 2933 | |
| 2934 | if (trim_len == 0) { |
| 2935 | return(DB_SUCCESScxx . . $ DB_SUCCESS.); |
| 2936 | } |
| 2937 | |
| 2938 | off += len; |
| 2939 | |
| 2940 | /* Check does file system support punching holes for this |
| 2941 | tablespace. */ |
| 2942 | if (!nodecxx . . $ IORequest#node.->punch_holecxx . . $ fil_node_t#punch_hole.) { |
| 2943 | return DB_IO_NO_PUNCH_HOLEcxx . . $ DB_IO_NO_PUNCH_HOLE.; |
| 2944 | } |
| 2945 | |
| 2946 | dberr_tcxx . . $ dberr_t# err = os_file_punch_holecxx . . $ os_file_punch_hole(f4234bfafe1749a0).(nodecxx . . $ IORequest#node.->handlecxx . . $ fil_node_t#handle., off, trim_len); |
| 2947 | |
| 2948 | switch (err) { |
| 2949 | case DB_SUCCESScxx . . $ DB_SUCCESS.: |
| 2950 | srv_statscxx . . $ srv_stats..page_compressed_trim_opcxx . . $ srv_stats_t#page_compressed_trim_op..inccxx . . $ ib_counter_t#inc(49f6e7a06ebc5aa8).(); |
| 2951 | return err; |
| 2952 | case DB_IO_NO_PUNCH_HOLEcxx . . $ DB_IO_NO_PUNCH_HOLE.: |
| 2953 | nodecxx . . $ IORequest#node.->punch_holecxx . . $ fil_node_t#punch_hole. = false; |
| 2954 | err = DB_SUCCESScxx . . $ DB_SUCCESS.; |
| 2955 | /* fall through */ |
| 2956 | default: |
| 2957 | return err; |
| 2958 | } |
| 2959 | } |
| 2960 | |
| 2961 | /* |
| 2962 | Get file system block size, by path. |
| 2963 | |
| 2964 | This is expensive on Windows, and not very useful in general, |
| 2965 | (only shown in some I_S table), so we keep that out of usual |
| 2966 | stat. |
| 2967 | */ |
| 2968 | size_t os_file_get_fs_block_sizecxx . . $ os_file_get_fs_block_size(751346f8406fd082).(const char *path) |
| 2969 | { |
| 2970 | #ifdef _WIN32 |
| 2971 | char volname[MAX_PATH]; |
| 2972 | if (!GetVolumePathName(path, volname, MAX_PATH)) |
| 2973 | return 0; |
| 2974 | DWORD sectorsPerCluster; |
| 2975 | DWORD bytesPerSector; |
| 2976 | DWORD numberOfFreeClusters; |
| 2977 | DWORD totalNumberOfClusters; |
| 2978 | |
| 2979 | if (GetDiskFreeSpace(volname, §orsPerCluster, &bytesPerSector, |
| 2980 | &numberOfFreeClusters, &totalNumberOfClusters)) |
| 2981 | return ((size_t) bytesPerSector) * sectorsPerCluster; |
| 2982 | #else |
| 2983 | os_file_stat_tcxx . . $ os_file_stat_t# info; |
| 2984 | if (os_file_get_statuscxx . . $ os_file_get_status(b4857cad02b801a9).(path, &info, false, false) == DB_SUCCESScxx . . $ DB_SUCCESS.) |
| 2985 | return info.block_sizecxx . . $ os_file_stat_t#block_size.; |
| 2986 | #endif |
| 2987 | return 0; |
| 2988 | } |
| 2989 | |
| 2990 | /** This function returns information about the specified file |
| 2991 | @param[in] path pathname of the file |
| 2992 | @param[out] stat_info information of a file in a directory |
| 2993 | @param[in] check_rw_perm for testing whether the file can be opened |
| 2994 | in RW mode |
| 2995 | @param[in] read_only true if file is opened in read-only mode |
| 2996 | @return DB_SUCCESS if all OK */ |
| 2997 | dberr_tcxx . . $ dberr_t# |
| 2998 | os_file_get_statuscxx . . $ os_file_get_status(b4857cad02b801a9).( |
| 2999 | const char* path, |
| 3000 | os_file_stat_tcxx . . $ os_file_stat_t#* stat_info, |
| 3001 | bool check_rw_perm, |
| 3002 | bool read_only) noexcept |
| 3003 | { |
| 3004 | dberr_tcxx . . $ dberr_t# ret; |
| 3005 | |
| 3006 | #ifdef _WIN32 |
| 3007 | struct _stat64 info; |
| 3008 | |
| 3009 | ret = os_file_get_status_win32( |
| 3010 | path, stat_info, &info, check_rw_perm, read_only); |
| 3011 | |
| 3012 | #else |
| 3013 | struct stat info; |
| 3014 | |
| 3015 | ret = os_file_get_status_posixcxx . . $ os_file_get_status_posix(7bcea40a702707b).( |
| 3016 | path, stat_info, &info, check_rw_perm, read_only); |
| 3017 | |
| 3018 | #endif /* _WIN32 */ |
| 3019 | |
| 3020 | if (ret == DB_SUCCESScxx . . $ DB_SUCCESS.) { |
| 3021 | stat_info->ctimecxx . . $ os_file_stat_t#ctime. = info.st_ctimecxx . . $ `<external>/16045971866008360577/struct_stat.h:79:11`!; |
| 3022 | stat_info->atimecxx . . $ os_file_stat_t#atime. = info.st_atimecxx . . $ `<external>/16045971866008360577/struct_stat.h:77:11`!; |
| 3023 | stat_info->mtimecxx . . $ os_file_stat_t#mtime. = info.st_mtimecxx . . $ `<external>/16045971866008360577/struct_stat.h:78:11`!; |
| 3024 | stat_info->sizecxx . . $ os_file_stat_t#size. = info.st_size; |
| 3025 | } |
| 3026 | |
| 3027 | return(ret); |
| 3028 | } |
| 3029 | |
| 3030 | static void fake_io_callbackcxx . . $ fake_io_callback(5d22bdacc48458e8).(void *c) |
| 3031 | { |
| 3032 | tpoolcxx . . $ tpool/::aiocbcxx . . $ tpool/aiocb# *cb= static_cast<tpoolcxx . . $ tpool/::aiocbcxx . . $ tpool/aiocb#*>(c); |
| 3033 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(read_slots->contains(cb)); |
| 3034 | static_cast<const IORequestcxx . . $ IORequest#*>(static_cast<const void*>(cb->m_userdatacxx . . $ tpool/aiocb#m_userdata.))-> |
| 3035 | fake_read_completecxx . . $ IORequest#fake_read_complete(d58b129fba78115d).(cb->m_offsetcxx . . $ tpool/aiocb#m_offset.); |
| 3036 | read_slotscxx . . $ read_slots.->releasecxx . . $ io_slots#release(38968c151d7b843b).(cb); |
| 3037 | } |
| 3038 | |
| 3039 | static void read_io_callbackcxx . . $ read_io_callback(5d22bdacc48458e8).(void *c) |
| 3040 | { |
| 3041 | tpoolcxx . . $ tpool/::aiocbcxx . . $ tpool/aiocb# *cb= static_cast<tpoolcxx . . $ tpool/::aiocbcxx . . $ tpool/aiocb#*>(c); |
| 3042 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(cb->m_opcode == tpool::aio_opcode::AIO_PREAD); |
| 3043 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(read_slots->contains(cb)); |
| 3044 | const IORequestcxx . . $ IORequest# &request= *static_cast<const IORequestcxx . . $ IORequest#*> |
| 3045 | (static_cast<const void*>(cb->m_userdatacxx . . $ tpool/aiocb#m_userdata.)); |
| 3046 | request.read_completecxx . . $ IORequest#read_complete(eeb694ac1692a88e).(cb->m_errcxx . . $ tpool/aiocb#m_err.); |
| 3047 | read_slotscxx . . $ read_slots.->releasecxx . . $ io_slots#release(38968c151d7b843b).(cb); |
| 3048 | } |
| 3049 | |
| 3050 | static void write_io_callbackcxx . . $ write_io_callback(5d22bdacc48458e8).(void *c) |
| 3051 | { |
| 3052 | tpoolcxx . . $ tpool/::aiocbcxx . . $ tpool/aiocb# *cb= static_cast<tpoolcxx . . $ tpool/::aiocbcxx . . $ tpool/aiocb#*>(c); |
| 3053 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(cb->m_opcode == tpool::aio_opcode::AIO_PWRITE); |
| 3054 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(write_slots->contains(cb)); |
| 3055 | const IORequestcxx . . $ IORequest# &request= *static_cast<const IORequestcxx . . $ IORequest#*> |
| 3056 | (static_cast<const void*>(cb->m_userdatacxx . . $ tpool/aiocb#m_userdata.)); |
| 3057 | |
| 3058 | if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(cb->m_err != 0)) |
| 3059 | ibcxx . . $ ib/::infocxx . . $ ib/info# () <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "IO Error: " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). cb->m_errcxx . . $ tpool/aiocb#m_err. |
| 3060 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " during write of " |
| 3061 | <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). cb->m_lencxx . . $ tpool/aiocb#m_len. <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " bytes, for file " |
| 3062 | <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). request.nodecxx . . $ IORequest#node.->namecxx . . $ fil_node_t#name. <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "(" <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). cb->m_fhcxx . . $ tpool/aiocb#m_fh. <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "), returned " |
| 3063 | <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). cb->m_ret_lencxx . . $ tpool/aiocb#m_ret_len.; |
| 3064 | |
| 3065 | request.write_completecxx . . $ IORequest#write_complete(eeb694ac1692a88e).(cb->m_errcxx . . $ tpool/aiocb#m_err.); |
| 3066 | write_slotscxx . . $ write_slots.->releasecxx . . $ io_slots#release(38968c151d7b843b).(cb); |
| 3067 | } |
| 3068 | |
| 3069 | int os_aio_initcxx . . $ os_aio_init(9efc7249d839d30e).() noexcept |
| 3070 | { |
| 3071 | int max_write_events= int(srv_n_write_io_threadscxx . . $ srv_n_write_io_threads. * |
| 3072 | OS_AIO_N_PENDING_IOS_PER_THREADcxx . . $ OS_AIO_N_PENDING_IOS_PER_THREAD.); |
| 3073 | int max_read_events= int(srv_n_read_io_threadscxx . . $ srv_n_read_io_threads. * |
| 3074 | OS_AIO_N_PENDING_IOS_PER_THREADcxx . . $ OS_AIO_N_PENDING_IOS_PER_THREAD.); |
| 3075 | int max_events= max_read_events + max_write_events; |
| 3076 | int ret= 1; |
| 3077 | |
| 3078 | if (srv_use_native_aiocxx . . $ srv_use_native_aio.) |
| 3079 | { |
| 3080 | tpoolcxx . . $ tpool/::aio_implementationcxx . . $ tpool/aio_implementation# aio_impl= tpoolcxx . . $ tpool/::OS_IO_DEFAULTcxx . . $ tpool/OS_IO_DEFAULT.; |
| 3081 | #ifdef __linux__cxx . . $ `<built-in>:465:9`! |
| 3082 | compile_time_assertcxx . . $ `include/my_global.h:377:9`!(SRV_LINUX_AIO_IO_URING == (srv_linux_aio_t)tpool::OS_IO_URING); |
| 3083 | compile_time_assertcxx . . $ `include/my_global.h:377:9`!(SRV_LINUX_AIO_LIBAIO == (srv_linux_aio_t) tpool::OS_IO_LIBAIO); |
| 3084 | compile_time_assertcxx . . $ `include/my_global.h:377:9`!(SRV_LINUX_AIO_AUTO == (srv_linux_aio_t) tpool::OS_IO_DEFAULT); |
| 3085 | aio_impl=(tpoolcxx . . $ tpool/::aio_implementationcxx . . $ tpool/aio_implementation#) srv_linux_aio_methodcxx . . $ srv_linux_aio_method.; |
| 3086 | #endif |
| 3087 | |
| 3088 | ret= srv_thread_poolcxx . . $ srv_thread_pool.->configure_aiocxx . . $ tpool/thread_pool#configure_aio(6d6b79e7500db560).(srv_use_native_aiocxx . . $ srv_use_native_aio., max_events, |
| 3089 | aio_impl); |
| 3090 | if (ret) |
| 3091 | { |
| 3092 | srv_use_native_aiocxx . . $ srv_use_native_aio.= false; |
| 3093 | sql_print_warningcxx . . $ sql_print_warning(326aeb464d16410c).("InnoDB: native AIO failed: falling back to" |
| 3094 | " innodb_use_native_aio=OFF"); |
| 3095 | } |
| 3096 | else |
| 3097 | sql_print_informationcxx . . $ sql_print_information(326aeb464d16410c).("InnoDB: Using %s", srv_thread_poolcxx . . $ srv_thread_pool. |
| 3098 | ->get_aio_implementationcxx . . $ tpool/thread_pool#get_aio_implementation(a9f41ea0e82d88cf).()); |
| 3099 | } |
| 3100 | if (ret) |
| 3101 | ret= srv_thread_poolcxx . . $ srv_thread_pool.->configure_aiocxx . . $ tpool/thread_pool#configure_aio(6d6b79e7500db560).(false, max_events, |
| 3102 | tpoolcxx . . $ tpool/::OS_IO_DEFAULTcxx . . $ tpool/OS_IO_DEFAULT.); |
| 3103 | if (!ret) |
| 3104 | { |
| 3105 | read_slotscxx . . $ read_slots.= new io_slotscxx . . $ io_slots#(max_read_events, srv_n_read_io_threadscxx . . $ srv_n_read_io_threads.); |
| 3106 | write_slotscxx . . $ write_slots.= new io_slotscxx . . $ io_slots#(max_write_events, srv_n_write_io_threadscxx . . $ srv_n_write_io_threads.); |
| 3107 | } |
| 3108 | else |
| 3109 | sql_print_errorcxx . . $ sql_print_error(326aeb464d16410c).("InnoDB: Cannot initialize AIO sub-system"); |
| 3110 | |
| 3111 | return ret; |
| 3112 | } |
| 3113 | |
| 3114 | |
| 3115 | /** |
| 3116 | Change reader or writer thread parameter on a running server. |
| 3117 | This includes resizing the io slots, as we calculate |
| 3118 | number of outstanding IOs based on the these variables. |
| 3119 | |
| 3120 | It is trickier with when Linux AIO is involved (io_context |
| 3121 | needs to be recreated to account for different number of |
| 3122 | max_events). With Linux AIO, depending on fs-max-aio number |
| 3123 | and user and system wide max-aio limitation, this can fail. |
| 3124 | |
| 3125 | Otherwise, we just resize the slots, and allow for |
| 3126 | more concurrent threads via thread_group setting. |
| 3127 | |
| 3128 | @param[in] n_reader_threads - max number of concurrently |
| 3129 | executing read callbacks |
| 3130 | @param[in] n_writer_thread - max number of cuncurrently |
| 3131 | executing write callbacks |
| 3132 | @return 0 for success, !=0 for error. |
| 3133 | */ |
| 3134 | int os_aio_resizecxx . . $ os_aio_resize(478c235635c778ac).(ulintcxx . . $ ulint# n_reader_threads, ulintcxx . . $ ulint# n_writer_threads) noexcept |
| 3135 | { |
| 3136 | /* Lock the slots, and wait until all current IOs finish.*/ |
| 3137 | stdcxx . . $ std/::unique_lockcxx . . $ std/unique_lock#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> lk_readcxx . . $ std/unique_lock#unique_lock(8e935d9c2e576e3a).(read_slotscxx . . $ read_slots.->mutexcxx . . $ io_slots#mutex(68c794e33b20812e).()), |
| 3138 | lk_writecxx . . $ std/unique_lock#unique_lock(8e935d9c2e576e3a).(write_slotscxx . . $ write_slots.->mutexcxx . . $ io_slots#mutex(68c794e33b20812e).()); |
| 3139 | |
| 3140 | read_slotscxx . . $ read_slots.->waitcxx . . $ io_slots#wait(f38159257778c065).(lk_read); |
| 3141 | write_slotscxx . . $ write_slots.->waitcxx . . $ io_slots#wait(f38159257778c065).(lk_write); |
| 3142 | |
| 3143 | /* Now, all IOs have finished and no new ones can start, due to locks. */ |
| 3144 | int max_read_events= int(n_reader_threads * OS_AIO_N_PENDING_IOS_PER_THREADcxx . . $ OS_AIO_N_PENDING_IOS_PER_THREAD.); |
| 3145 | int max_write_events= int(n_writer_threads * OS_AIO_N_PENDING_IOS_PER_THREADcxx . . $ OS_AIO_N_PENDING_IOS_PER_THREAD.); |
| 3146 | int events= max_read_events + max_write_events; |
| 3147 | |
| 3148 | /* Do the Linux AIO dance (this will try to create a new |
| 3149 | io context with changed max_events, etc.) */ |
| 3150 | |
| 3151 | int ret= srv_thread_poolcxx . . $ srv_thread_pool.->reconfigure_aiocxx . . $ tpool/thread_pool#reconfigure_aio(f2f3906b81fb2c87).(srv_use_native_aiocxx . . $ srv_use_native_aio., events); |
| 3152 | |
| 3153 | if (ret) |
| 3154 | { |
| 3155 | /** Do the best effort. We can't change the parallel io number, |
| 3156 | but we still can adjust the number of concurrent completion handlers.*/ |
| 3157 | read_slotscxx . . $ read_slots.->task_groupcxx . . $ io_slots#task_group(e3e597138b917ae1).().set_max_taskscxx . . $ tpool/task_group#set_max_tasks(cb2f890c2fdad230).(static_cast<int>(n_reader_threads)); |
| 3158 | write_slotscxx . . $ write_slots.->task_groupcxx . . $ io_slots#task_group(e3e597138b917ae1).().set_max_taskscxx . . $ tpool/task_group#set_max_tasks(cb2f890c2fdad230).(static_cast<int>(n_writer_threads)); |
| 3159 | } |
| 3160 | else |
| 3161 | { |
| 3162 | /* Allocation succeeded, resize the slots*/ |
| 3163 | read_slotscxx . . $ read_slots.->resizecxx . . $ io_slots#resize(3e454b8ccf442868).(max_read_events, static_cast<int>(n_reader_threads)); |
| 3164 | write_slotscxx . . $ write_slots.->resizecxx . . $ io_slots#resize(3e454b8ccf442868).(max_write_events, static_cast<int>(n_writer_threads)); |
| 3165 | } |
| 3166 | return ret; |
| 3167 | } |
| 3168 | |
| 3169 | void os_aio_freecxx . . $ os_aio_free(ced63f7c635d850d).() noexcept |
| 3170 | { |
| 3171 | delete read_slotscxx . . $ read_slots.; |
| 3172 | delete write_slotscxx . . $ write_slots.; |
| 3173 | read_slotscxx . . $ read_slots.= nullptr; |
| 3174 | write_slotscxx . . $ write_slots.= nullptr; |
| 3175 | srv_thread_poolcxx . . $ srv_thread_pool.->disable_aiocxx . . $ tpool/thread_pool#disable_aio(49f6e7a06ebc5aa8).(); |
| 3176 | } |
| 3177 | |
| 3178 | /** Wait until there are no pending asynchronous writes. */ |
| 3179 | static void os_aio_wait_until_no_pending_writes_lowcxx . . $ os_aio_wait_until_no_pending_writes_low(9f0ba574c1c44ffc).(bool declare) noexcept |
| 3180 | { |
| 3181 | const bool notify_wait= declare && write_slotscxx . . $ write_slots.->pending_io_countcxx . . $ io_slots#pending_io_count(f708dce9a8856c70).(); |
| 3182 | |
| 3183 | if (notify_wait) |
| 3184 | tpoolcxx . . $ tpool/::tpool_wait_begin(); |
| 3185 | |
| 3186 | write_slotscxx . . $ write_slots.->waitcxx . . $ io_slots#wait(49f6e7a06ebc5aa8).(); |
| 3187 | |
| 3188 | if (notify_wait) |
| 3189 | tpoolcxx . . $ tpool/::tpool_wait_end(); |
| 3190 | } |
| 3191 | |
| 3192 | /** Wait until there are no pending asynchronous writes. |
| 3193 | @param declare whether the wait will be declared in tpool */ |
| 3194 | void os_aio_wait_until_no_pending_writescxx . . $ os_aio_wait_until_no_pending_writes(9f0ba574c1c44ffc).(bool declare) noexcept |
| 3195 | { |
| 3196 | os_aio_wait_until_no_pending_writes_lowcxx . . $ os_aio_wait_until_no_pending_writes_low(9f0ba574c1c44ffc).(declare); |
| 3197 | buf_dblwrcxx . . $ buf_dblwr..wait_flush_buffered_writescxx . . $ buf_dblwr_t#wait_flush_buffered_writes(ced63f7c635d850d).(); |
| 3198 | } |
| 3199 | |
| 3200 | /** @return number of pending reads */ |
| 3201 | size_t os_aio_pending_readscxx . . $ os_aio_pending_reads(cee159cc271e827).() noexcept |
| 3202 | { |
| 3203 | stdcxx . . $ std/::lock_guardcxx . . $ std/lock_guard#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> lockcxx . . $ std/lock_guard#lock_guard(8e935d9c2e576e3a).(read_slotscxx . . $ read_slots.->mutexcxx . . $ io_slots#mutex(68c794e33b20812e).()); |
| 3204 | return read_slotscxx . . $ read_slots.->pending_io_countcxx . . $ io_slots#pending_io_count(f708dce9a8856c70).(); |
| 3205 | } |
| 3206 | |
| 3207 | /** @return approximate number of pending reads */ |
| 3208 | size_t os_aio_pending_reads_approxcxx . . $ os_aio_pending_reads_approx(cee159cc271e827).() noexcept |
| 3209 | { |
| 3210 | return read_slotscxx . . $ read_slots.->pending_io_countcxx . . $ io_slots#pending_io_count(f708dce9a8856c70).(); |
| 3211 | } |
| 3212 | |
| 3213 | /** @return number of pending writes */ |
| 3214 | size_t os_aio_pending_writescxx . . $ os_aio_pending_writes(cee159cc271e827).() noexcept |
| 3215 | { |
| 3216 | stdcxx . . $ std/::lock_guardcxx . . $ std/lock_guard#<stdcxx . . $ std/::mutexcxx . . $ std/mutex#> lockcxx . . $ std/lock_guard#lock_guard(8e935d9c2e576e3a).(write_slotscxx . . $ write_slots.->mutexcxx . . $ io_slots#mutex(68c794e33b20812e).()); |
| 3217 | return write_slotscxx . . $ write_slots.->pending_io_countcxx . . $ io_slots#pending_io_count(f708dce9a8856c70).(); |
| 3218 | } |
| 3219 | |
| 3220 | /** @return approximate number of pending writes */ |
| 3221 | size_t os_aio_pending_writes_approxcxx . . $ os_aio_pending_writes_approx(cee159cc271e827).() noexcept |
| 3222 | { |
| 3223 | return write_slotscxx . . $ write_slots.->pending_io_countcxx . . $ io_slots#pending_io_count(f708dce9a8856c70).(); |
| 3224 | } |
| 3225 | |
| 3226 | /** Wait until all pending asynchronous reads have completed. |
| 3227 | @param declare whether the wait will be declared in tpool */ |
| 3228 | void os_aio_wait_until_no_pending_readscxx . . $ os_aio_wait_until_no_pending_reads(9f0ba574c1c44ffc).(bool declare) noexcept |
| 3229 | { |
| 3230 | const bool notify_wait= declare && read_slotscxx . . $ read_slots.->pending_io_countcxx . . $ io_slots#pending_io_count(f708dce9a8856c70).(); |
| 3231 | |
| 3232 | if (notify_wait) |
| 3233 | tpoolcxx . . $ tpool/::tpool_wait_begin(); |
| 3234 | |
| 3235 | read_slotscxx . . $ read_slots.->waitcxx . . $ io_slots#wait(49f6e7a06ebc5aa8).(); |
| 3236 | |
| 3237 | if (notify_wait) |
| 3238 | tpoolcxx . . $ tpool/::tpool_wait_end(); |
| 3239 | } |
| 3240 | |
| 3241 | /** Submit a fake read request during crash recovery. |
| 3242 | @param type fake read request |
| 3243 | @param offset additional context */ |
| 3244 | void os_fake_readcxx . . $ os_fake_read(74152e700ba92bdb).(const IORequestcxx . . $ IORequest# &type, os_offset_tcxx . . $ os_offset_t# offset) noexcept |
| 3245 | { |
| 3246 | tpoolcxx . . $ tpool/::aiocbcxx . . $ tpool/aiocb# *cb= read_slotscxx . . $ read_slots.->acquirecxx . . $ io_slots#acquire(8b2b19b7e814d8a1).(); |
| 3247 | |
| 3248 | cb->m_groupcxx . . $ tpool/aiocb#m_group.= read_slotscxx . . $ read_slots.->get_task_groupcxx . . $ io_slots#get_task_group(91bc7f57de24ed43).(); |
| 3249 | cb->m_fhcxx . . $ tpool/aiocb#m_fh.= type.nodecxx . . $ IORequest#node.->handlecxx . . $ fil_node_t#handle..m_filecxx . . $ pfs_os_file_t#m_file.; |
| 3250 | cb->m_buffercxx . . $ tpool/aiocb#m_buffer.= nullptr; |
| 3251 | cb->m_lencxx . . $ tpool/aiocb#m_len.= 0; |
| 3252 | cb->m_offsetcxx . . $ tpool/aiocb#m_offset.= offset; |
| 3253 | cb->m_opcodecxx . . $ tpool/aiocb#m_opcode.= tpoolcxx . . $ tpool/::aio_opcodecxx . . $ tpool/aio_opcode#::AIO_PREADcxx . . $ tpool/aio_opcode#AIO_PREAD.; |
| 3254 | new (cb->m_userdatacxx . . $ tpool/aiocb#m_userdata.) IORequestcxx . . $ IORequest#{type}; |
| 3255 | cb->m_internal_taskcxx . . $ tpool/aiocb#m_internal_task..m_funccxx . . $ tpool/task#m_func.= fake_io_callbackcxx . . $ fake_io_callback(5d22bdacc48458e8).; |
| 3256 | cb->m_internal_taskcxx . . $ tpool/aiocb#m_internal_task..m_argcxx . . $ tpool/task#m_arg.= cb; |
| 3257 | cb->m_internal_taskcxx . . $ tpool/aiocb#m_internal_task..m_groupcxx . . $ tpool/task#m_group.= cb->m_groupcxx . . $ tpool/aiocb#m_group.; |
| 3258 | |
| 3259 | srv_thread_poolcxx . . $ srv_thread_pool.->submit_taskcxx . . $ tpool/thread_pool#submit_task(b575c5a2f6d6c59e).(&cb->m_internal_taskcxx . . $ tpool/aiocb#m_internal_task.); |
| 3260 | } |
| 3261 | |
| 3262 | |
| 3263 | /** Request a read or write. |
| 3264 | @param type I/O request |
| 3265 | @param buf buffer |
| 3266 | @param offset file offset |
| 3267 | @param n number of bytes |
| 3268 | @retval DB_SUCCESS if request was queued successfully |
| 3269 | @retval DB_IO_ERROR on I/O error */ |
| 3270 | dberr_tcxx . . $ dberr_t# os_aiocxx . . $ os_aio(c1a527f3e39de94e).(const IORequestcxx . . $ IORequest# &type, void *buf, os_offset_tcxx . . $ os_offset_t# offset, size_t n) |
| 3271 | noexcept |
| 3272 | { |
| 3273 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(n > 0); |
| 3274 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!(n & 511)); /* payload of page_compressed tables */ |
| 3275 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!((offset % UNIV_ZIP_SIZE_MIN) == 0); |
| 3276 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!((reinterpret_cast<size_t>(buf) % UNIV_ZIP_SIZE_MIN) == 0); |
| 3277 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(type.is_read() || type.is_write()); |
| 3278 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(type.node); |
| 3279 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(type.node->is_open()); |
| 3280 | |
| 3281 | #ifdef WIN_ASYNC_IO |
| 3282 | ut_ad((n & 0xFFFFFFFFUL) == n); |
| 3283 | #endif /* WIN_ASYNC_IO */ |
| 3284 | |
| 3285 | #ifdef UNIV_PFS_IOcxx . . $ `storage/innobase/include/univ.i:70:10`! |
| 3286 | PSI_file_locker_state state; |
| 3287 | PSI_file_locker* locker= nullptr; |
| 3288 | register_pfs_file_io_begincxx . . $ `storage/innobase/include/os0file.h:515:10`!(&state, locker, type.node->handle, n, |
| 3289 | type.is_write() |
| 3290 | ? PSI_FILE_WRITE : PSI_FILE_READ, |
| 3291 | __FILE__, __LINE__); |
| 3292 | #endif /* UNIV_PFS_IO */ |
| 3293 | dberr_tcxx . . $ dberr_t# err = DB_SUCCESScxx . . $ DB_SUCCESS.; |
| 3294 | |
| 3295 | if (!type.is_asynccxx . . $ IORequest#is_async(3482b152b9333168).()) { |
| 3296 | err = type.is_readcxx . . $ IORequest#is_read(3482b152b9333168).() |
| 3297 | ? os_file_read_funccxx . . $ os_file_read_func(8dd0cab60fa19858).(type, type.nodecxx . . $ IORequest#node.->handlecxx . . $ fil_node_t#handle., |
| 3298 | buf, offset, n, nullptr) |
| 3299 | : os_file_write_funccxx . . $ os_file_write_func(27b9ed7ec5c91f27).(type, type.nodecxx . . $ IORequest#node.->namecxx . . $ fil_node_t#name., |
| 3300 | type.nodecxx . . $ IORequest#node.->handlecxx . . $ fil_node_t#handle., |
| 3301 | buf, offset, n); |
| 3302 | func_exit: |
| 3303 | #ifdef UNIV_PFS_IOcxx . . $ `storage/innobase/include/univ.i:70:10`! |
| 3304 | register_pfs_file_io_endcxx . . $ `storage/innobase/include/os0file.h:526:10`!(locker, n); |
| 3305 | #endif /* UNIV_PFS_IO */ |
| 3306 | return err; |
| 3307 | } |
| 3308 | |
| 3309 | io_slotscxx . . $ io_slots#* slots; |
| 3310 | tpoolcxx . . $ tpool/::callback_funccxx . . $ tpool/callback_func# callback; |
| 3311 | tpoolcxx . . $ tpool/::aio_opcodecxx . . $ tpool/aio_opcode# opcode; |
| 3312 | |
| 3313 | if (type.is_readcxx . . $ IORequest#is_read(3482b152b9333168).()) { |
| 3314 | ++cxx . . $ Atomic_counter#operator++(5f357b03ed472e5e).os_n_file_readscxx . . $ os_n_file_reads.; |
| 3315 | slots = read_slotscxx . . $ read_slots.; |
| 3316 | callback = read_io_callbackcxx . . $ read_io_callback(5d22bdacc48458e8).; |
| 3317 | opcode = tpoolcxx . . $ tpool/::aio_opcodecxx . . $ tpool/aio_opcode#::AIO_PREADcxx . . $ tpool/aio_opcode#AIO_PREAD.; |
| 3318 | } else { |
| 3319 | ++cxx . . $ Atomic_counter#operator++(5f357b03ed472e5e).os_n_file_writescxx . . $ os_n_file_writes.; |
| 3320 | slots = write_slotscxx . . $ write_slots.; |
| 3321 | callback = write_io_callbackcxx . . $ write_io_callback(5d22bdacc48458e8).; |
| 3322 | opcode = tpoolcxx . . $ tpool/::aio_opcodecxx . . $ tpool/aio_opcode#::AIO_PWRITEcxx . . $ tpool/aio_opcode#AIO_PWRITE.; |
| 3323 | } |
| 3324 | |
| 3325 | compile_time_assertcxx . . $ `include/my_global.h:377:9`!(sizeof(IORequest) <= tpool::MAX_AIO_USERDATA_LEN); |
| 3326 | tpoolcxx . . $ tpool/::aiocbcxx . . $ tpool/aiocb#* cb = slots->acquirecxx . . $ io_slots#acquire(8b2b19b7e814d8a1).(); |
| 3327 | |
| 3328 | cb->m_buffercxx . . $ tpool/aiocb#m_buffer. = buf; |
| 3329 | cb->m_callbackcxx . . $ tpool/aiocb#m_callback. = callback; |
| 3330 | cb->m_groupcxx . . $ tpool/aiocb#m_group. = slots->get_task_groupcxx . . $ io_slots#get_task_group(91bc7f57de24ed43).(); |
| 3331 | cb->m_fhcxx . . $ tpool/aiocb#m_fh. = type.nodecxx . . $ IORequest#node.->handlecxx . . $ fil_node_t#handle..m_filecxx . . $ pfs_os_file_t#m_file.; |
| 3332 | cb->m_lencxx . . $ tpool/aiocb#m_len. = (int)n; |
| 3333 | cb->m_offsetcxx . . $ tpool/aiocb#m_offset. = offset; |
| 3334 | cb->m_opcodecxx . . $ tpool/aiocb#m_opcode. = opcode; |
| 3335 | new (cb->m_userdatacxx . . $ tpool/aiocb#m_userdata.) IORequestcxx . . $ IORequest#{type}; |
| 3336 | |
| 3337 | if (srv_thread_poolcxx . . $ srv_thread_pool.->submit_iocxx . . $ tpool/thread_pool#submit_io(f2db4c24b1da440b).(cb)) { |
| 3338 | slots->releasecxx . . $ io_slots#release(38968c151d7b843b).(cb); |
| 3339 | os_file_handle_error_no_exitcxx . . $ os_file_handle_error_no_exit(567fbfac950d45).(type.nodecxx . . $ IORequest#node.->namecxx . . $ fil_node_t#name., type.is_readcxx . . $ IORequest#is_read(3482b152b9333168).() |
| 3340 | ? "aio read" : "aio write", |
| 3341 | false); |
| 3342 | err = DB_IO_ERRORcxx . . $ DB_IO_ERROR.; |
| 3343 | type.nodecxx . . $ IORequest#node.->spacecxx . . $ fil_node_t#space.->releasecxx . . $ fil_space_t#release(77ce49a7840d23c7).(); |
| 3344 | } |
| 3345 | |
| 3346 | goto func_exit; |
| 3347 | } |
| 3348 | |
| 3349 | void os_aio_printcxx . . $ os_aio_print(d40dfdaba0afe397).(FILE *file) noexcept |
| 3350 | { |
| 3351 | time_tcxx . . $ time_t# current_time; |
| 3352 | double time_elapsed; |
| 3353 | |
| 3354 | current_time = time(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 3355 | time_elapsed = 0.001 + difftime(current_time, os_last_printoutcxx . . $ os_last_printout.); |
| 3356 | |
| 3357 | fprintf(file, |
| 3358 | "Pending flushes (fsync): " ULINTPFcxx . . $ `storage/innobase/include/univ.i:290:9`! "\n" |
| 3359 | ULINTPFcxx . . $ `storage/innobase/include/univ.i:290:9`! " OS file reads, %zu OS file writes, %zu OS fsyncs\n", |
| 3360 | ulintcxx . . $ ulint#{fil_n_pending_tablespace_flushescxx . . $ fil_n_pending_tablespace_flushes.}, |
| 3361 | ulintcxx . . $ ulint#{os_n_file_readscxx . . $ os_n_file_reads.}, |
| 3362 | static_cast<size_t>(os_n_file_writescxx . . $ os_n_file_writes.), |
| 3363 | static_cast<size_t>(os_n_fsyncscxx . . $ os_n_fsyncs.)); |
| 3364 | |
| 3365 | const ulintcxx . . $ ulint# n_reads = ulintcxx . . $ ulint#(MONITOR_VALUEcxx . . $ `storage/innobase/include/srv0mon.h:449:9`!(MONITOR_OS_PENDING_READS)); |
| 3366 | const ulintcxx . . $ ulint# n_writes = ulintcxx . . $ ulint#(MONITOR_VALUEcxx . . $ `storage/innobase/include/srv0mon.h:449:9`!(MONITOR_OS_PENDING_WRITES)); |
| 3367 | |
| 3368 | if (n_reads != 0 || n_writes != 0) { |
| 3369 | fprintf(file, |
| 3370 | ULINTPFcxx . . $ `storage/innobase/include/univ.i:290:9`! " pending reads, " ULINTPFcxx . . $ `storage/innobase/include/univ.i:290:9`! " pending writes\n", |
| 3371 | n_reads, n_writes); |
| 3372 | } |
| 3373 | |
| 3374 | ulintcxx . . $ ulint# avg_bytes_read = (os_n_file_readscxx . . $ os_n_file_reads. == os_n_file_reads_oldcxx . . $ os_n_file_reads_old.) |
| 3375 | ? 0 |
| 3376 | : os_bytes_read_since_printoutcxx . . $ os_bytes_read_since_printout. |
| 3377 | / (os_n_file_readscxx . . $ os_n_file_reads. - os_n_file_reads_oldcxx . . $ os_n_file_reads_old.); |
| 3378 | |
| 3379 | fprintf(file, |
| 3380 | "%.2f reads/s, " ULINTPFcxx . . $ `storage/innobase/include/univ.i:290:9`! " avg bytes/read," |
| 3381 | " %.2f writes/s, %.2f fsyncs/s\n", |
| 3382 | static_cast<double>(os_n_file_readscxx . . $ os_n_file_reads. - os_n_file_reads_oldcxx . . $ os_n_file_reads_old.) |
| 3383 | / time_elapsed, |
| 3384 | avg_bytes_read, |
| 3385 | static_cast<double>(os_n_file_writescxx . . $ os_n_file_writes. - os_n_file_writes_oldcxx . . $ os_n_file_writes_old.) |
| 3386 | / time_elapsed, |
| 3387 | static_cast<double>(os_n_fsyncscxx . . $ os_n_fsyncs. - os_n_fsyncs_oldcxx . . $ os_n_fsyncs_old.) |
| 3388 | / time_elapsed); |
| 3389 | |
| 3390 | os_n_file_reads_oldcxx . . $ os_n_file_reads_old. = os_n_file_readscxx . . $ os_n_file_reads.; |
| 3391 | os_n_file_writes_oldcxx . . $ os_n_file_writes_old. = os_n_file_writescxx . . $ os_n_file_writes.; |
| 3392 | os_n_fsyncs_oldcxx . . $ os_n_fsyncs_old. = os_n_fsyncscxx . . $ os_n_fsyncs.; |
| 3393 | os_bytes_read_since_printoutcxx . . $ os_bytes_read_since_printout. = 0; |
| 3394 | |
| 3395 | os_last_printoutcxx . . $ os_last_printout. = current_time; |
| 3396 | } |
| 3397 | |
| 3398 | void os_aio_refresh_statscxx . . $ os_aio_refresh_stats(ced63f7c635d850d).() noexcept |
| 3399 | { |
| 3400 | os_n_fsyncs_oldcxx . . $ os_n_fsyncs_old. = os_n_fsyncscxx . . $ os_n_fsyncs.; |
| 3401 | |
| 3402 | os_bytes_read_since_printoutcxx . . $ os_bytes_read_since_printout. = 0; |
| 3403 | |
| 3404 | os_n_file_reads_oldcxx . . $ os_n_file_reads_old. = os_n_file_readscxx . . $ os_n_file_reads.; |
| 3405 | |
| 3406 | os_n_file_writes_oldcxx . . $ os_n_file_writes_old. = os_n_file_writescxx . . $ os_n_file_writes.; |
| 3407 | |
| 3408 | os_n_fsyncs_oldcxx . . $ os_n_fsyncs_old. = os_n_fsyncscxx . . $ os_n_fsyncs.; |
| 3409 | |
| 3410 | os_bytes_read_since_printoutcxx . . $ os_bytes_read_since_printout. = 0; |
| 3411 | |
| 3412 | os_last_printoutcxx . . $ os_last_printout. = time(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 3413 | } |
| 3414 | |
| 3415 | #ifdef _WIN32 |
| 3416 | |
| 3417 | /* Checks whether physical drive is on SSD.*/ |
| 3418 | static bool is_drive_on_ssd(DWORD nr) |
| 3419 | { |
| 3420 | char physical_drive_path[32]; |
| 3421 | snprintf(physical_drive_path, sizeof(physical_drive_path), |
| 3422 | "\\\\.\\PhysicalDrive%lu", nr); |
| 3423 | |
| 3424 | HANDLE h= CreateFile(physical_drive_path, 0, |
| 3425 | FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 3426 | nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr); |
| 3427 | if (h == INVALID_HANDLE_VALUE) |
| 3428 | return false; |
| 3429 | |
| 3430 | DEVICE_SEEK_PENALTY_DESCRIPTOR seek_penalty; |
| 3431 | STORAGE_PROPERTY_QUERY storage_query{}; |
| 3432 | storage_query.PropertyId= StorageDeviceSeekPenaltyProperty; |
| 3433 | storage_query.QueryType= PropertyStandardQuery; |
| 3434 | |
| 3435 | bool on_ssd= false; |
| 3436 | DWORD bytes_written; |
| 3437 | if (DeviceIoControl(h, IOCTL_STORAGE_QUERY_PROPERTY, &storage_query, |
| 3438 | sizeof storage_query, &seek_penalty, sizeof seek_penalty, |
| 3439 | &bytes_written, nullptr)) |
| 3440 | { |
| 3441 | on_ssd= !seek_penalty.IncursSeekPenalty; |
| 3442 | } |
| 3443 | else |
| 3444 | { |
| 3445 | on_ssd= false; |
| 3446 | } |
| 3447 | CloseHandle(h); |
| 3448 | return on_ssd; |
| 3449 | } |
| 3450 | |
| 3451 | /* |
| 3452 | Checks whether volume is on SSD, by checking all physical drives |
| 3453 | in that volume. |
| 3454 | */ |
| 3455 | static bool is_volume_on_ssd(const char *volume_mount_point) |
| 3456 | { |
| 3457 | char volume_name[MAX_PATH]; |
| 3458 | |
| 3459 | if (!GetVolumeNameForVolumeMountPoint(volume_mount_point, volume_name, |
| 3460 | array_elements(volume_name))) |
| 3461 | { |
| 3462 | /* This can fail, e.g if file is on network share */ |
| 3463 | return false; |
| 3464 | } |
| 3465 | |
| 3466 | /* Chomp last backslash, this is needed to open volume.*/ |
| 3467 | size_t length= strlen(volume_name); |
| 3468 | if (length && volume_name[length - 1] == '\\') |
| 3469 | volume_name[length - 1]= 0; |
| 3470 | |
| 3471 | /* Open volume handle */ |
| 3472 | HANDLE volume_handle= CreateFile( |
| 3473 | volume_name, 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 3474 | nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr); |
| 3475 | |
| 3476 | if (volume_handle == INVALID_HANDLE_VALUE) |
| 3477 | return false; |
| 3478 | |
| 3479 | /* |
| 3480 | Enumerate all volume extends, check whether all of them are on SSD |
| 3481 | */ |
| 3482 | |
| 3483 | /* Anticipate common case where there is only one extent.*/ |
| 3484 | VOLUME_DISK_EXTENTS single_extent; |
| 3485 | |
| 3486 | /* But also have a place to manage allocated data.*/ |
| 3487 | std::unique_ptr<BYTE[]> lifetime; |
| 3488 | |
| 3489 | DWORD bytes_written; |
| 3490 | VOLUME_DISK_EXTENTS *extents= nullptr; |
| 3491 | if (DeviceIoControl(volume_handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, |
| 3492 | nullptr, 0, &single_extent, sizeof(single_extent), |
| 3493 | &bytes_written, nullptr)) |
| 3494 | { |
| 3495 | /* Worked on the first try. Use the preallocated buffer.*/ |
| 3496 | extents= &single_extent; |
| 3497 | } |
| 3498 | else |
| 3499 | { |
| 3500 | VOLUME_DISK_EXTENTS *last_query= &single_extent; |
| 3501 | while (GetLastError() == ERROR_MORE_DATA) |
| 3502 | { |
| 3503 | DWORD extentCount= last_query->NumberOfDiskExtents; |
| 3504 | DWORD allocatedSize= |
| 3505 | FIELD_OFFSET(VOLUME_DISK_EXTENTS, Extents[extentCount]); |
| 3506 | lifetime.reset(new BYTE[allocatedSize]); |
| 3507 | last_query= (VOLUME_DISK_EXTENTS *) lifetime.get(); |
| 3508 | if (DeviceIoControl(volume_handle, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, |
| 3509 | nullptr, 0, last_query, allocatedSize, |
| 3510 | &bytes_written, nullptr)) |
| 3511 | { |
| 3512 | extents= last_query; |
| 3513 | break; |
| 3514 | } |
| 3515 | } |
| 3516 | } |
| 3517 | CloseHandle(volume_handle); |
| 3518 | if (!extents) |
| 3519 | return false; |
| 3520 | |
| 3521 | for (DWORD i= 0; i < extents->NumberOfDiskExtents; i++) |
| 3522 | if (!is_drive_on_ssd(extents->Extents[i].DiskNumber)) |
| 3523 | return false; |
| 3524 | |
| 3525 | return true; |
| 3526 | } |
| 3527 | |
| 3528 | #include <unordered_map> |
| 3529 | static bool is_path_on_ssd(char *file_path) |
| 3530 | { |
| 3531 | /* Preset result, in case something fails, e.g we're on network drive.*/ |
| 3532 | char volume_path[MAX_PATH]; |
| 3533 | if (!GetVolumePathName(file_path, volume_path, array_elements(volume_path))) |
| 3534 | return false; |
| 3535 | return is_volume_on_ssd(volume_path); |
| 3536 | } |
| 3537 | |
| 3538 | static bool is_file_on_ssd(HANDLE handle, char *file_path) |
| 3539 | { |
| 3540 | ULONGLONG volume_serial_number; |
| 3541 | FILE_ID_INFO info; |
| 3542 | if(!GetFileInformationByHandleEx(handle, FileIdInfo, &info, sizeof(info))) |
| 3543 | return false; |
| 3544 | volume_serial_number= info.VolumeSerialNumber; |
| 3545 | |
| 3546 | static std::unordered_map<ULONGLONG, bool> cache; |
| 3547 | static SRWLOCK lock= SRWLOCK_INIT; |
| 3548 | bool found; |
| 3549 | bool result; |
| 3550 | AcquireSRWLockShared(&lock); |
| 3551 | auto e= cache.find(volume_serial_number); |
| 3552 | if ((found= e != cache.end())) |
| 3553 | result= e->second; |
| 3554 | ReleaseSRWLockShared(&lock); |
| 3555 | if (!found) |
| 3556 | { |
| 3557 | result= is_path_on_ssd(file_path); |
| 3558 | /* Update cache */ |
| 3559 | AcquireSRWLockExclusive(&lock); |
| 3560 | cache[volume_serial_number]= result; |
| 3561 | ReleaseSRWLockExclusive(&lock); |
| 3562 | } |
| 3563 | return result; |
| 3564 | } |
| 3565 | |
| 3566 | #endif |
| 3567 | |
| 3568 | void fil_node_tcxx . . $ fil_node_t#::find_metadatacxx . . $ fil_node_t#find_metadata(9f0ba574c1c44ffc).(IF_WINcxx . . $ `include/my_global.h:97:9`!(,bool create)) noexcept |
| 3569 | { |
| 3570 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(is_open()); |
| 3571 | os_file_tcxx . . $ os_file_t# file= handlecxx . . $ fil_node_t#handle.; |
| 3572 | |
| 3573 | if (!spacecxx . . $ fil_node_t#space.->is_compressedcxx . . $ fil_space_t#is_compressed(3482b152b9333168).()) |
| 3574 | punch_holecxx . . $ fil_node_t#punch_hole.= 0; |
| 3575 | else if (my_test_if_thinly_provisioned(file)) |
| 3576 | punch_holecxx . . $ fil_node_t#punch_hole.= 2; |
| 3577 | else |
| 3578 | punch_holecxx . . $ fil_node_t#punch_hole.= IF_WINcxx . . $ `include/my_global.h:97:9`!(, !create ||) os_is_sparse_file_supportedcxx . . $ os_is_sparse_file_supported(109becb148f4ca36).(file); |
| 3579 | /* For temporary tablespace or during IMPORT TABLESPACE, we |
| 3580 | disable neighbour flushing and do not care about atomicity. */ |
| 3581 | if (spacecxx . . $ fil_node_t#space.->is_temporarycxx . . $ fil_space_t#is_temporary(3482b152b9333168).()) |
| 3582 | { |
| 3583 | on_ssdcxx . . $ fil_node_t#on_ssd.= true; |
| 3584 | atomic_writecxx . . $ fil_node_t#atomic_write.= true; |
| 3585 | return; |
| 3586 | } |
| 3587 | if (spacecxx . . $ fil_node_t#space.->is_being_importedcxx . . $ fil_space_t#is_being_imported(3482b152b9333168).()) |
| 3588 | { |
| 3589 | on_ssdcxx . . $ fil_node_t#on_ssd.= true; |
| 3590 | atomic_writecxx . . $ fil_node_t#atomic_write.= true; |
| 3591 | if (!spacecxx . . $ fil_node_t#space.->is_compressedcxx . . $ fil_space_t#is_compressed(3482b152b9333168).()) |
| 3592 | return; |
| 3593 | } |
| 3594 | #ifdef _WIN32 |
| 3595 | on_ssd= is_file_on_ssd(file, name); |
| 3596 | FILE_STORAGE_INFO info; |
| 3597 | if (GetFileInformationByHandleEx(file, FileStorageInfo, &info, sizeof info)) |
| 3598 | block_size= info.PhysicalBytesPerSectorForAtomicity; |
| 3599 | else |
| 3600 | block_size= 512; |
| 3601 | #else |
| 3602 | struct stat statbuf; |
| 3603 | if (!fstat(file, &statbuf)) |
| 3604 | { |
| 3605 | block_sizecxx . . $ fil_node_t#block_size.= statbuf.st_blksize; |
| 3606 | # ifdef __linux__cxx . . $ `<built-in>:465:9`! |
| 3607 | on_ssdcxx . . $ fil_node_t#on_ssd.= fil_systemcxx . . $ fil_system..is_ssdcxx . . $ fil_system_t#is_ssd(9d5f7ce526bbb82a).(statbuf.st_dev); |
| 3608 | # endif |
| 3609 | } |
| 3610 | #endif |
| 3611 | |
| 3612 | /* On Windows, all single sector writes are atomic, as per |
| 3613 | WriteFile() documentation on MSDN. */ |
| 3614 | atomic_writecxx . . $ fil_node_t#atomic_write.= srv_use_atomic_writescxx . . $ srv_use_atomic_writes. && |
| 3615 | IF_WINcxx . . $ `include/my_global.h:97:9`!(srv_page_size == block_size, |
| 3616 | my_test_if_atomic_write(file, space->physical_size())); |
| 3617 | } |
| 3618 | |
| 3619 | /** Read the first page of a data file. |
| 3620 | @return whether the page was found valid */ |
| 3621 | bool fil_node_tcxx . . $ fil_node_t#::read_page0cxx . . $ fil_node_t#read_page0(dc35541a7e0d3731).(const bytecxx . . $ byte# *dpage, bool no_lsn) noexcept |
| 3622 | { |
| 3623 | mysql_mutex_assert_ownercxx . . $ `include/mysql/psi/mysql_thread.h:273:9`!(&fil_system.mutex); |
| 3624 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!dpage || no_lsn); |
| 3625 | const unsigned psize= spacecxx . . $ fil_node_t#space.->physical_sizecxx . . $ fil_space_t#physical_size(d22c8608b6eae7b5).(); |
| 3626 | os_offset_tcxx . . $ os_offset_t# size_bytes= os_file_get_sizecxx . . $ os_file_get_size(a516d6ace67a1470).(handlecxx . . $ fil_node_t#handle.); |
| 3627 | if (size_bytes == os_offset_tcxx . . $ os_offset_t#(-1)) |
| 3628 | return false; |
| 3629 | const uint32_tcxx . . $ uint32_t# min_size= FIL_IBD_FILE_INITIAL_SIZEcxx . . $ `storage/innobase/include/fil0fil.h:1172:9`! * psize; |
| 3630 | |
| 3631 | if (size_bytes < min_size) |
| 3632 | { |
| 3633 | ibcxx . . $ ib/::errorcxx . . $ ib/error#() <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). "The size of the file " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). namecxx . . $ fil_node_t#name. |
| 3634 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " is only " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). size_bytes |
| 3635 | <<cxx . . $ ib/logger#`operator<<`(dcbc6b5678e2764). " bytes, should be at least " <<cxx . . $ ib/logger#`operator<<`(8dc2c095a0caceff). min_size; |
| 3636 | return false; |
| 3637 | } |
| 3638 | |
| 3639 | if (!deferredcxx . . $ fil_node_t#deferred.) |
| 3640 | { |
| 3641 | page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`! *apage= static_cast<bytecxx . . $ byte#*>(aligned_malloccxx . . $ aligned_malloc(63a7bf2941bfcd7a).(psize, psize)); |
| 3642 | if (os_file_readcxx . . $ `storage/innobase/include/os0file.h:568:10`!(IORequestRead, handle, apage, 0, psize, nullptr) != |
| 3643 | DB_SUCCESScxx . . $ DB_SUCCESS.) |
| 3644 | { |
| 3645 | sql_print_errorcxx . . $ sql_print_error(326aeb464d16410c).("InnoDB: Unable to read first page of file %s", namecxx . . $ fil_node_t#name.); |
| 3646 | err_exit: |
| 3647 | aligned_freecxx . . $ aligned_free(5d22bdacc48458e8).(apage); |
| 3648 | return false; |
| 3649 | } |
| 3650 | |
| 3651 | const page_tcxx . . $ `storage/innobase/include/page0types.h:38:9`! *page= apage; |
| 3652 | retry: |
| 3653 | const ulintcxx . . $ ulint# space_id= memcmp_alignedcxx . . $ memcmp_aligned(36f949851efa3055).<2> |
| 3654 | (FIL_PAGE_SPACE_IDcxx . . $ `storage/innobase/include/fil0fil.h:1247:9`! + page, |
| 3655 | FSP_HEADER_OFFSETcxx . . $ `storage/innobase/include/fsp0fsp.h:102:9`! + FSP_SPACE_IDcxx . . $ `storage/innobase/include/fsp0fsp.h:115:9`! + page, 4) |
| 3656 | ? ULINT_UNDEFINEDcxx . . $ `storage/innobase/include/univ.i:329:9`! |
| 3657 | : mach_read_from_4cxx . . $ mach_read_from_4(ca1608e2c87725e2).(FIL_PAGE_SPACE_IDcxx . . $ `storage/innobase/include/fil0fil.h:1247:9`! + page); |
| 3658 | uint32_tcxx . . $ uint32_t# flags= fsp_header_get_flagscxx . . $ fsp_header_get_flags(ca1608e2c87725e2).(page); |
| 3659 | const uint32_tcxx . . $ uint32_t# size= fsp_header_get_fieldcxx . . $ fsp_header_get_field(13d9c8ea4fc589cf).(page, FSP_SIZEcxx . . $ `storage/innobase/include/fsp0fsp.h:120:9`!); |
| 3660 | if (!space_id && !flags && !size && dpage) |
| 3661 | { |
| 3662 | retry_dpage: |
| 3663 | page= dpage; |
| 3664 | dpage= nullptr; |
| 3665 | goto retry; |
| 3666 | } |
| 3667 | const uint32_tcxx . . $ uint32_t# free_limit= fsp_header_get_fieldcxx . . $ fsp_header_get_field(13d9c8ea4fc589cf).(page, FSP_FREE_LIMITcxx . . $ `storage/innobase/include/fsp0fsp.h:122:9`!); |
| 3668 | const uint32_tcxx . . $ uint32_t# free_len= flst_get_lencxx . . $ flst_get_len(ca1608e2c87725e2).(FSP_HEADER_OFFSETcxx . . $ `storage/innobase/include/fsp0fsp.h:102:9`! + FSP_FREEcxx . . $ `storage/innobase/include/fsp0fsp.h:136:9`! + page); |
| 3669 | |
| 3670 | if (!fil_space_tcxx . . $ fil_space_t#::is_valid_flagscxx . . $ fil_space_t#is_valid_flags(c534903ed7350fb0).(flags, spacecxx . . $ fil_node_t#space.->idcxx . . $ fil_space_t#id.)) |
| 3671 | { |
| 3672 | uint32_tcxx . . $ uint32_t# cflags= fsp_flags_convert_from_101cxx . . $ fsp_flags_convert_from_101(2141b656ce2cc063).(flags); |
| 3673 | if (cflags != UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!) |
| 3674 | { |
| 3675 | uint32_tcxx . . $ uint32_t# cf= cflags & ~FSP_FLAGS_MEM_MASKcxx . . $ `storage/innobase/include/fsp0types.h:270:9`!; |
| 3676 | uint32_tcxx . . $ uint32_t# sf= spacecxx . . $ fil_node_t#space.->flagscxx . . $ fil_space_t#flags. & ~FSP_FLAGS_MEM_MASKcxx . . $ `storage/innobase/include/fsp0types.h:270:9`!; |
| 3677 | |
| 3678 | if (fil_space_tcxx . . $ fil_space_t#::is_flags_equalcxx . . $ fil_space_t#is_flags_equal(d92a6f4903462276).(cf, sf) || |
| 3679 | fil_space_tcxx . . $ fil_space_t#::is_flags_equalcxx . . $ fil_space_t#is_flags_equal(d92a6f4903462276).(sf, cf)) |
| 3680 | { |
| 3681 | flags= cflags; |
| 3682 | goto flags_ok; |
| 3683 | } |
| 3684 | } |
| 3685 | |
| 3686 | goto invalid; |
| 3687 | } |
| 3688 | |
| 3689 | if (!fil_space_tcxx . . $ fil_space_t#::is_flags_equalcxx . . $ fil_space_t#is_flags_equal(d92a6f4903462276).((flags & ~FSP_FLAGS_MEM_MASKcxx . . $ `storage/innobase/include/fsp0types.h:270:9`!), |
| 3690 | (spacecxx . . $ fil_node_t#space.->flagscxx . . $ fil_space_t#flags. & ~FSP_FLAGS_MEM_MASKcxx . . $ `storage/innobase/include/fsp0types.h:270:9`!)) && |
| 3691 | !fil_space_tcxx . . $ fil_space_t#::is_flags_equalcxx . . $ fil_space_t#is_flags_equal(d92a6f4903462276).((spacecxx . . $ fil_node_t#space.->flagscxx . . $ fil_space_t#flags. & ~FSP_FLAGS_MEM_MASKcxx . . $ `storage/innobase/include/fsp0types.h:270:9`!), |
| 3692 | (flags & ~FSP_FLAGS_MEM_MASKcxx . . $ `storage/innobase/include/fsp0types.h:270:9`!))) |
| 3693 | { |
| 3694 | invalid: |
| 3695 | if (dpage) |
| 3696 | goto retry_dpage; |
| 3697 | sql_print_errorcxx . . $ sql_print_error(326aeb464d16410c).("InnoDB: Expected tablespace flags 0x%" PRIx32cxx . . $ `<external>/15933738808807975373/inttypes.h:120:10`! |
| 3698 | " but found 0x%" PRIx32cxx . . $ `<external>/15933738808807975373/inttypes.h:120:10`! |
| 3699 | " in the file %s", spacecxx . . $ fil_node_t#space.->flagscxx . . $ fil_space_t#flags., flags, namecxx . . $ fil_node_t#name.); |
| 3700 | goto err_exit; |
| 3701 | } |
| 3702 | |
| 3703 | flags_ok: |
| 3704 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(!(flags & FSP_FLAGS_MEM_MASK)); |
| 3705 | |
| 3706 | if (buf_page_is_corruptedcxx . . $ buf_page_is_corrupted(714b375f2102dbcf).(!no_lsn, page, flags) != NOT_CORRUPTEDcxx . . $ NOT_CORRUPTED.) |
| 3707 | { |
| 3708 | if (dpage) |
| 3709 | goto retry_dpage; |
| 3710 | sql_print_errorcxx . . $ sql_print_error(326aeb464d16410c).("InnoDB: The first page of file %s is corrupted", namecxx . . $ fil_node_t#name.); |
| 3711 | goto err_exit; |
| 3712 | } |
| 3713 | |
| 3714 | if (UNIV_UNLIKELYcxx . . $ `storage/innobase/include/univ.i:439:9`!(space_id != space->id)) |
| 3715 | { |
| 3716 | if (dpage) |
| 3717 | goto retry_dpage; |
| 3718 | sql_print_errorcxx . . $ sql_print_error(326aeb464d16410c).("InnoDB: Expected tablespace id %zu but found %zu" |
| 3719 | " in the file %s", ulintcxx . . $ ulint#{spacecxx . . $ fil_node_t#space.->idcxx . . $ fil_space_t#id.}, ulintcxx . . $ ulint#{space_id}, |
| 3720 | namecxx . . $ fil_node_t#name.); |
| 3721 | goto err_exit; |
| 3722 | } |
| 3723 | |
| 3724 | /* Try to read crypt_data from page 0 if it is not yet read. */ |
| 3725 | if (!spacecxx . . $ fil_node_t#space.->crypt_datacxx . . $ fil_space_t#crypt_data.) |
| 3726 | spacecxx . . $ fil_node_t#space.->crypt_datacxx . . $ fil_space_t#crypt_data.= fil_space_read_crypt_datacxx . . $ fil_space_read_crypt_data(1109c76aac6a686).( |
| 3727 | fil_space_tcxx . . $ fil_space_t#::zip_sizecxx . . $ fil_space_t#zip_size(6e3776fd289463bb).(flags), page); |
| 3728 | aligned_freecxx . . $ aligned_free(5d22bdacc48458e8).(apage); |
| 3729 | |
| 3730 | spacecxx . . $ fil_node_t#space.->flagscxx . . $ fil_space_t#flags.= (spacecxx . . $ fil_node_t#space.->flagscxx . . $ fil_space_t#flags. & FSP_FLAGS_MEM_MASKcxx . . $ `storage/innobase/include/fsp0types.h:270:9`!) | flags; |
| 3731 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(space->free_limit == 0 || space->free_limit == free_limit); |
| 3732 | ut_adcxx . . $ `storage/innobase/include/ut0dbg.h:62:9`!(space->free_len == 0 || space->free_len == free_len); |
| 3733 | spacecxx . . $ fil_node_t#space.->size_in_headercxx . . $ fil_space_t#size_in_header.= size; |
| 3734 | spacecxx . . $ fil_node_t#space.->free_limitcxx . . $ fil_space_t#free_limit.= free_limit; |
| 3735 | spacecxx . . $ fil_node_t#space.->free_lencxx . . $ fil_space_t#free_len.= free_len; |
| 3736 | } |
| 3737 | |
| 3738 | find_metadatacxx . . $ fil_node_t#find_metadata(9f0ba574c1c44ffc).(); |
| 3739 | /* Truncate the size to a multiple of extent size. */ |
| 3740 | ulintcxx . . $ ulint# mask= psize * FSP_EXTENT_SIZEcxx . . $ `storage/innobase/include/fsp0types.h:67:9`! - 1; |
| 3741 | |
| 3742 | if (size_bytes <= mask); |
| 3743 | /* .ibd files start smaller than an |
| 3744 | extent size. Do not truncate valid data. */ |
| 3745 | else |
| 3746 | size_bytes&= ~os_offset_tcxx . . $ os_offset_t#(mask); |
| 3747 | |
| 3748 | this->sizecxx . . $ fil_node_t#size.= uint32_tcxx . . $ uint32_t#(size_bytes / psize); |
| 3749 | spacecxx . . $ fil_node_t#space.->set_sizescxx . . $ fil_space_t#set_sizes(6bab9b75950d6f3).(this->sizecxx . . $ fil_node_t#size.); |
| 3750 | return true; |
| 3751 | } |