| 1 | /* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. |
| 2 | |
| 3 | This program is free software; you can redistribute it and/or modify |
| 4 | it under the terms of the GNU General Public License as published by |
| 5 | the Free Software Foundation; version 2 of the License. |
| 6 | |
| 7 | This program is distributed in the hope that it will be useful, |
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | GNU General Public License for more details. |
| 11 | |
| 12 | You should have received a copy of the GNU General Public License |
| 13 | along with this program; if not, write to the Free Software Foundation, |
| 14 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ |
| 15 | |
| 16 | #ifndef MYSQL_FILE_H |
| 17 | #define MYSQL_FILE_H |
| 18 | |
| 19 | /* For strlen() */ |
| 20 | #include <string.h> |
| 21 | /* For MY_STAT */ |
| 22 | #include <my_dir.h> |
| 23 | /* For my_chsize */ |
| 24 | #include <my_sys.h> |
| 25 | |
| 26 | /** |
| 27 | @file mysql/psi/mysql_file.h |
| 28 | Instrumentation helpers for mysys file io. |
| 29 | This header file provides the necessary declarations |
| 30 | to use the mysys file API with the performance schema instrumentation. |
| 31 | In some compilers (SunStudio), 'static inline' functions, when declared |
| 32 | but not used, are not optimized away (because they are unused) by default, |
| 33 | so that including a static inline function from a header file does |
| 34 | create unwanted dependencies, causing unresolved symbols at link time. |
| 35 | Other compilers, like gcc, optimize these dependencies by default. |
| 36 | |
| 37 | Since the instrumented APIs declared here are wrapper on top |
| 38 | of mysys file io APIs, including mysql/psi/mysql_file.h assumes that |
| 39 | the dependency on my_sys already exists. |
| 40 | */ |
| 41 | |
| 42 | #include "mysql/psi/psi.h" |
| 43 | |
| 44 | /** |
| 45 | @defgroup File_instrumentation File Instrumentation |
| 46 | @ingroup Instrumentation_interface |
| 47 | @{ |
| 48 | */ |
| 49 | |
| 50 | /** |
| 51 | @def mysql_file_register(P1, P2, P3) |
| 52 | File registration. |
| 53 | */ |
| 54 | #define mysql_file_register(P1, P2, P3) \ |
| 55 | inline_mysql_file_register(P1, P2, P3) |
| 56 | |
| 57 | /** |
| 58 | @def mysql_file_fgets(P1, P2, F) |
| 59 | Instrumented fgets. |
| 60 | @c mysql_file_fgets is a replacement for @c fgets. |
| 61 | */ |
| 62 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 63 | #define mysql_file_fgets(P1, P2, F) \ |
| 64 | inline_mysql_file_fgets(__FILE__, __LINE__, P1, P2, F) |
| 65 | #else |
| 66 | #define mysql_file_fgets(P1, P2, F) \ |
| 67 | inline_mysql_file_fgets(P1, P2, F) |
| 68 | #endif |
| 69 | |
| 70 | /** |
| 71 | @def mysql_file_fgetc(F) |
| 72 | Instrumented fgetc. |
| 73 | @c mysql_file_fgetc is a replacement for @c fgetc. |
| 74 | */ |
| 75 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 76 | #define mysql_file_fgetc(F) inline_mysql_file_fgetc(__FILE__, __LINE__, F) |
| 77 | #else |
| 78 | #define mysql_file_fgetc(F) inline_mysql_file_fgetc(F) |
| 79 | #endif |
| 80 | |
| 81 | /** |
| 82 | @def mysql_file_fputs(P1, F) |
| 83 | Instrumented fputs. |
| 84 | @c mysql_file_fputs is a replacement for @c fputs. |
| 85 | */ |
| 86 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 87 | #define mysql_file_fputs(P1, F) \ |
| 88 | inline_mysql_file_fputs(__FILE__, __LINE__, P1, F) |
| 89 | #else |
| 90 | #define mysql_file_fputs(P1, F)\ |
| 91 | inline_mysql_file_fputs(P1, F) |
| 92 | #endif |
| 93 | |
| 94 | /** |
| 95 | @def mysql_file_fputc(P1, F) |
| 96 | Instrumented fputc. |
| 97 | @c mysql_file_fputc is a replacement for @c fputc. |
| 98 | */ |
| 99 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 100 | #define mysql_file_fputc(P1, F) \ |
| 101 | inline_mysql_file_fputc(__FILE__, __LINE__, P1, F) |
| 102 | #else |
| 103 | #define mysql_file_fputc(P1, F) \ |
| 104 | inline_mysql_file_fputc(P1, F) |
| 105 | #endif |
| 106 | |
| 107 | /** |
| 108 | @def mysql_file_fprintf |
| 109 | Instrumented fprintf. |
| 110 | @c mysql_file_fprintf is a replacement for @c fprintf. |
| 111 | */ |
| 112 | #define mysql_file_fprintf inline_mysql_file_fprintf |
| 113 | |
| 114 | /** |
| 115 | @def mysql_file_vfprintf(F, P1, P2) |
| 116 | Instrumented vfprintf. |
| 117 | @c mysql_file_vfprintf is a replacement for @c vfprintf. |
| 118 | */ |
| 119 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 120 | #define mysql_file_vfprintf(F, P1, P2) \ |
| 121 | inline_mysql_file_vfprintf(__FILE__, __LINE__, F, P1, P2) |
| 122 | #else |
| 123 | #define mysql_file_vfprintf(F, P1, P2) \ |
| 124 | inline_mysql_file_vfprintf(F, P1, P2) |
| 125 | #endif |
| 126 | |
| 127 | /** |
| 128 | @def mysql_file_fflush(F, P1, P2) |
| 129 | Instrumented fflush. |
| 130 | @c mysql_file_fflush is a replacement for @c fflush. |
| 131 | */ |
| 132 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 133 | #define mysql_file_fflush(F) \ |
| 134 | inline_mysql_file_fflush(__FILE__, __LINE__, F) |
| 135 | #else |
| 136 | #define mysql_file_fflush(F) \ |
| 137 | inline_mysql_file_fflush(F) |
| 138 | #endif |
| 139 | |
| 140 | /** |
| 141 | @def mysql_file_feof(F) |
| 142 | Instrumented feof. |
| 143 | @c mysql_file_feof is a replacement for @c feof. |
| 144 | */ |
| 145 | #define mysql_file_feof(F) inline_mysql_file_feof(F) |
| 146 | |
| 147 | /** |
| 148 | @def mysql_file_fstat(FN, S, FL) |
| 149 | Instrumented fstat. |
| 150 | @c mysql_file_fstat is a replacement for @c my_fstat. |
| 151 | */ |
| 152 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 153 | #define mysql_file_fstat(FN, S, FL) \ |
| 154 | inline_mysql_file_fstat(__FILE__, __LINE__, FN, S, FL) |
| 155 | #else |
| 156 | #define mysql_file_fstat(FN, S, FL) \ |
| 157 | inline_mysql_file_fstat(FN, S, FL) |
| 158 | #endif |
| 159 | |
| 160 | /** |
| 161 | @def mysql_file_stat(K, FN, S, FL) |
| 162 | Instrumented stat. |
| 163 | @c mysql_file_stat is a replacement for @c my_stat. |
| 164 | */ |
| 165 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 166 | #define mysql_file_stat(K, FN, S, FL) \ |
| 167 | inline_mysql_file_stat(K, __FILE__, __LINE__, FN, S, FL) |
| 168 | #else |
| 169 | #define mysql_file_stat(K, FN, S, FL) \ |
| 170 | inline_mysql_file_stat(FN, S, FL) |
| 171 | #endif |
| 172 | |
| 173 | /** |
| 174 | @def mysql_file_chsize(F, P1, P2, P3) |
| 175 | Instrumented chsize. |
| 176 | @c mysql_file_chsize is a replacement for @c my_chsize. |
| 177 | */ |
| 178 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 179 | #define mysql_file_chsize(F, P1, P2, P3) \ |
| 180 | inline_mysql_file_chsize(__FILE__, __LINE__, F, P1, P2, P3) |
| 181 | #else |
| 182 | #define mysql_file_chsize(F, P1, P2, P3) \ |
| 183 | inline_mysql_file_chsize(F, P1, P2, P3) |
| 184 | #endif |
| 185 | |
| 186 | /** |
| 187 | @def mysql_file_fopen(K, N, F1, F2) |
| 188 | Instrumented fopen. |
| 189 | @c mysql_file_fopen is a replacement for @c my_fopen. |
| 190 | */ |
| 191 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 192 | #define mysql_file_fopen(K, N, F1, F2) \ |
| 193 | inline_mysql_file_fopen(K, __FILE__, __LINE__, N, F1, F2) |
| 194 | #else |
| 195 | #define mysql_file_fopen(K, N, F1, F2) \ |
| 196 | inline_mysql_file_fopen(N, F1, F2) |
| 197 | #endif |
| 198 | |
| 199 | /** |
| 200 | @def mysql_file_fclose(FD, FL) |
| 201 | Instrumented fclose. |
| 202 | @c mysql_file_fclose is a replacement for @c my_fclose. |
| 203 | Without the instrumentation, this call will have the same behavior as the |
| 204 | undocumented and possibly platform specific my_fclose(NULL, ...) behavior. |
| 205 | With the instrumentation, mysql_fclose(NULL, ...) will safely return 0, |
| 206 | which is an extension compared to my_fclose and is therefore compliant. |
| 207 | mysql_fclose is on purpose *not* implementing |
| 208 | @code DBUG_ASSERT(file != NULL) @endcode, |
| 209 | since doing so could introduce regressions. |
| 210 | */ |
| 211 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 212 | #define mysql_file_fclose(FD, FL) \ |
| 213 | inline_mysql_file_fclose(__FILE__, __LINE__, FD, FL) |
| 214 | #else |
| 215 | #define mysql_file_fclose(FD, FL) \ |
| 216 | inline_mysql_file_fclose(FD, FL) |
| 217 | #endif |
| 218 | |
| 219 | /** |
| 220 | @def mysql_file_fread(FD, P1, P2, P3) |
| 221 | Instrumented fread. |
| 222 | @c mysql_file_fread is a replacement for @c my_fread. |
| 223 | */ |
| 224 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 225 | #define mysql_file_fread(FD, P1, P2, P3) \ |
| 226 | inline_mysql_file_fread(__FILE__, __LINE__, FD, P1, P2, P3) |
| 227 | #else |
| 228 | #define mysql_file_fread(FD, P1, P2, P3) \ |
| 229 | inline_mysql_file_fread(FD, P1, P2, P3) |
| 230 | #endif |
| 231 | |
| 232 | /** |
| 233 | @def mysql_file_fwrite(FD, P1, P2, P3) |
| 234 | Instrumented fwrite. |
| 235 | @c mysql_file_fwrite is a replacement for @c my_fwrite. |
| 236 | */ |
| 237 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 238 | #define mysql_file_fwrite(FD, P1, P2, P3) \ |
| 239 | inline_mysql_file_fwrite(__FILE__, __LINE__, FD, P1, P2, P3) |
| 240 | #else |
| 241 | #define mysql_file_fwrite(FD, P1, P2, P3) \ |
| 242 | inline_mysql_file_fwrite(FD, P1, P2, P3) |
| 243 | #endif |
| 244 | |
| 245 | /** |
| 246 | @def mysql_file_fseek(FD, P, W, F) |
| 247 | Instrumented fseek. |
| 248 | @c mysql_file_fseek is a replacement for @c my_fseek. |
| 249 | */ |
| 250 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 251 | #define mysql_file_fseek(FD, P, W, F) \ |
| 252 | inline_mysql_file_fseek(__FILE__, __LINE__, FD, P, W, F) |
| 253 | #else |
| 254 | #define mysql_file_fseek(FD, P, W, F) \ |
| 255 | inline_mysql_file_fseek(FD, P, W, F) |
| 256 | #endif |
| 257 | |
| 258 | /** |
| 259 | @def mysql_file_ftell(FD, F) |
| 260 | Instrumented ftell. |
| 261 | @c mysql_file_ftell is a replacement for @c my_ftell. |
| 262 | */ |
| 263 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 264 | #define mysql_file_ftell(FD, F) \ |
| 265 | inline_mysql_file_ftell(__FILE__, __LINE__, FD, F) |
| 266 | #else |
| 267 | #define mysql_file_ftell(FD, F) \ |
| 268 | inline_mysql_file_ftell(FD, F) |
| 269 | #endif |
| 270 | |
| 271 | /** |
| 272 | @def mysql_file_create(K, N, F1, F2, F3) |
| 273 | Instrumented create. |
| 274 | @c mysql_file_create is a replacement for @c my_create. |
| 275 | */ |
| 276 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 277 | #define mysql_file_create(K, N, F1, F2, F3) \ |
| 278 | inline_mysql_file_create(K, __FILE__, __LINE__, N, F1, F2, F3) |
| 279 | #else |
| 280 | #define mysql_file_create(K, N, F1, F2, F3) \ |
| 281 | inline_mysql_file_create(N, F1, F2, F3) |
| 282 | #endif |
| 283 | |
| 284 | /** |
| 285 | @def mysql_file_create_temp(K, T, D, P, M, F) |
| 286 | Instrumented create_temp_file. |
| 287 | @c mysql_file_create_temp is a replacement for @c create_temp_file. |
| 288 | */ |
| 289 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 290 | #define mysql_file_create_temp(K, T, D, P, M, F) \ |
| 291 | inline_mysql_file_create_temp(K, T, D, P, M, F) |
| 292 | #else |
| 293 | #define mysql_file_create_temp(K, T, D, P, M, F) \ |
| 294 | inline_mysql_file_create_temp(T, D, P, M, F) |
| 295 | #endif |
| 296 | |
| 297 | /** |
| 298 | @def mysql_file_open(K, N, F1, F2) |
| 299 | Instrumented open. |
| 300 | @c mysql_file_open is a replacement for @c my_open. |
| 301 | */ |
| 302 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 303 | #define mysql_file_open(K, N, F1, F2) \ |
| 304 | inline_mysql_file_open(K, __FILE__, __LINE__, N, F1, F2) |
| 305 | #else |
| 306 | #define mysql_file_open(K, N, F1, F2) \ |
| 307 | inline_mysql_file_open(N, F1, F2) |
| 308 | #endif |
| 309 | |
| 310 | /** |
| 311 | @def mysql_file_close(FD, F) |
| 312 | Instrumented close. |
| 313 | @c mysql_file_close is a replacement for @c my_close. |
| 314 | */ |
| 315 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 316 | #define mysql_file_close(FD, F) \ |
| 317 | inline_mysql_file_close(__FILE__, __LINE__, FD, F) |
| 318 | #else |
| 319 | #define mysql_file_close(FD, F) \ |
| 320 | inline_mysql_file_close(FD, F) |
| 321 | #endif |
| 322 | |
| 323 | /** |
| 324 | @def mysql_file_read(FD, B, S, F) |
| 325 | Instrumented read. |
| 326 | @c mysql_read is a replacement for @c my_read. |
| 327 | */ |
| 328 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 329 | #define mysql_file_read(FD, B, S, F) \ |
| 330 | inline_mysql_file_read(__FILE__, __LINE__, FD, B, S, F) |
| 331 | #else |
| 332 | #define mysql_file_read(FD, B, S, F) \ |
| 333 | inline_mysql_file_read(FD, B, S, F) |
| 334 | #endif |
| 335 | |
| 336 | /** |
| 337 | @def mysql_file_write(FD, B, S, F) |
| 338 | Instrumented write. |
| 339 | @c mysql_file_write is a replacement for @c my_write. |
| 340 | */ |
| 341 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 342 | #define mysql_file_write(FD, B, S, F) \ |
| 343 | inline_mysql_file_write(__FILE__, __LINE__, FD, B, S, F) |
| 344 | #else |
| 345 | #define mysql_file_write(FD, B, S, F) \ |
| 346 | inline_mysql_file_write(FD, B, S, F) |
| 347 | #endif |
| 348 | |
| 349 | /** |
| 350 | @def mysql_file_pread(FD, B, S, O, F) |
| 351 | Instrumented pread. |
| 352 | @c mysql_pread is a replacement for @c my_pread. |
| 353 | */ |
| 354 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 355 | #define mysql_file_pread(FD, B, S, O, F) \ |
| 356 | inline_mysql_file_pread(__FILE__, __LINE__, FD, B, S, O, F) |
| 357 | #else |
| 358 | #define mysql_file_pread(FD, B, S, O, F) \ |
| 359 | inline_mysql_file_pread(FD, B, S, O, F) |
| 360 | #endif |
| 361 | |
| 362 | /** |
| 363 | @def mysql_file_pwrite(FD, B, S, O, F) |
| 364 | Instrumented pwrite. |
| 365 | @c mysql_file_pwrite is a replacement for @c my_pwrite. |
| 366 | */ |
| 367 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 368 | #define mysql_file_pwrite(FD, B, S, O, F) \ |
| 369 | inline_mysql_file_pwrite(__FILE__, __LINE__, FD, B, S, O, F) |
| 370 | #else |
| 371 | #define mysql_file_pwrite(FD, B, S, O, F) \ |
| 372 | inline_mysql_file_pwrite(FD, B, S, O, F) |
| 373 | #endif |
| 374 | |
| 375 | /** |
| 376 | @def mysql_file_seek(FD, P, W, F) |
| 377 | Instrumented seek. |
| 378 | @c mysql_file_seek is a replacement for @c my_seek. |
| 379 | */ |
| 380 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 381 | #define mysql_file_seek(FD, P, W, F) \ |
| 382 | inline_mysql_file_seek(__FILE__, __LINE__, FD, P, W, F) |
| 383 | #else |
| 384 | #define mysql_file_seek(FD, P, W, F) \ |
| 385 | inline_mysql_file_seek(FD, P, W, F) |
| 386 | #endif |
| 387 | |
| 388 | /** |
| 389 | @def mysql_file_tell(FD, F) |
| 390 | Instrumented tell. |
| 391 | @c mysql_file_tell is a replacement for @c my_tell. |
| 392 | */ |
| 393 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 394 | #define mysql_file_tell(FD, F) \ |
| 395 | inline_mysql_file_tell(__FILE__, __LINE__, FD, F) |
| 396 | #else |
| 397 | #define mysql_file_tell(FD, F) \ |
| 398 | inline_mysql_file_tell(FD, F) |
| 399 | #endif |
| 400 | |
| 401 | /** |
| 402 | @def mysql_file_delete(K, P1, P2) |
| 403 | Instrumented delete. |
| 404 | @c mysql_file_delete is a replacement for @c my_delete. |
| 405 | */ |
| 406 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 407 | #define mysql_file_delete(K, P1, P2) \ |
| 408 | inline_mysql_file_delete(K, __FILE__, __LINE__, P1, P2) |
| 409 | #else |
| 410 | #define mysql_file_delete(K, P1, P2) \ |
| 411 | inline_mysql_file_delete(P1, P2) |
| 412 | #endif |
| 413 | |
| 414 | /** |
| 415 | @def mysql_file_rename(K, P1, P2, P3) |
| 416 | Instrumented rename. |
| 417 | @c mysql_file_rename is a replacement for @c my_rename. |
| 418 | */ |
| 419 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 420 | #define mysql_file_rename(K, P1, P2, P3) \ |
| 421 | inline_mysql_file_rename(K, __FILE__, __LINE__, P1, P2, P3) |
| 422 | #else |
| 423 | #define mysql_file_rename(K, P1, P2, P3) \ |
| 424 | inline_mysql_file_rename(P1, P2, P3) |
| 425 | #endif |
| 426 | |
| 427 | /** |
| 428 | @def mysql_file_create_with_symlink(K, P1, P2, P3, P4, P5) |
| 429 | Instrumented create with symbolic link. |
| 430 | @c mysql_file_create_with_symlink is a replacement |
| 431 | for @c my_create_with_symlink. |
| 432 | */ |
| 433 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 434 | #define mysql_file_create_with_symlink(K, P1, P2, P3, P4, P5) \ |
| 435 | inline_mysql_file_create_with_symlink(K, __FILE__, __LINE__, \ |
| 436 | P1, P2, P3, P4, P5) |
| 437 | #else |
| 438 | #define mysql_file_create_with_symlink(K, P1, P2, P3, P4, P5) \ |
| 439 | inline_mysql_file_create_with_symlink(P1, P2, P3, P4, P5) |
| 440 | #endif |
| 441 | |
| 442 | /** |
| 443 | @def mysql_file_delete_with_symlink(K, P1, P2, P3) |
| 444 | Instrumented delete with symbolic link. |
| 445 | @c mysql_file_delete_with_symlink is a replacement |
| 446 | for @c my_handler_delete_with_symlink. |
| 447 | */ |
| 448 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 449 | #define mysql_file_delete_with_symlink(K, P1, P2, P3) \ |
| 450 | inline_mysql_file_delete_with_symlink(K, __FILE__, __LINE__, P1, P2, P3) |
| 451 | #else |
| 452 | #define mysql_file_delete_with_symlink(K, P1, P2, P3) \ |
| 453 | inline_mysql_file_delete_with_symlink(P1, P2, P3) |
| 454 | #endif |
| 455 | |
| 456 | /** |
| 457 | @def mysql_file_rename_with_symlink(K, P1, P2, P3) |
| 458 | Instrumented rename with symbolic link. |
| 459 | @c mysql_file_rename_with_symlink is a replacement |
| 460 | for @c my_rename_with_symlink. |
| 461 | */ |
| 462 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 463 | #define mysql_file_rename_with_symlink(K, P1, P2, P3) \ |
| 464 | inline_mysql_file_rename_with_symlink(K, __FILE__, __LINE__, P1, P2, P3) |
| 465 | #else |
| 466 | #define mysql_file_rename_with_symlink(K, P1, P2, P3) \ |
| 467 | inline_mysql_file_rename_with_symlink(P1, P2, P3) |
| 468 | #endif |
| 469 | |
| 470 | /** |
| 471 | @def mysql_file_sync(P1, P2) |
| 472 | Instrumented file sync. |
| 473 | @c mysql_file_sync is a replacement for @c my_sync. |
| 474 | */ |
| 475 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 476 | #define mysql_file_sync(P1, P2) \ |
| 477 | inline_mysql_file_sync(__FILE__, __LINE__, P1, P2) |
| 478 | #else |
| 479 | #define mysql_file_sync(P1, P2) \ |
| 480 | inline_mysql_file_sync(P1, P2) |
| 481 | #endif |
| 482 | |
| 483 | /** |
| 484 | An instrumented FILE structure. |
| 485 | @sa MYSQL_FILE |
| 486 | */ |
| 487 | struct st_mysql_file |
| 488 | { |
| 489 | /** The real file. */ |
| 490 | FILE *m_file; |
| 491 | /** |
| 492 | The instrumentation hook. |
| 493 | Note that this hook is not conditionally defined, |
| 494 | for binary compatibility of the @c MYSQL_FILE interface. |
| 495 | */ |
| 496 | struct PSI_file *m_psi; |
| 497 | }; |
| 498 | |
| 499 | /** |
| 500 | Type of an instrumented file. |
| 501 | @c MYSQL_FILE is a drop-in replacement for @c FILE. |
| 502 | @sa mysql_file_open |
| 503 | */ |
| 504 | typedef struct st_mysql_file MYSQL_FILE; |
| 505 | |
| 506 | static inline void inline_mysql_file_register( |
| 507 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 508 | const char *category, |
| 509 | PSI_file_info *info, |
| 510 | int count |
| 511 | #else |
| 512 | const char *category __attribute__ ((unused)), |
| 513 | void *info __attribute__ ((unused)), |
| 514 | int count __attribute__ ((unused)) |
| 515 | #endif |
| 516 | ) |
| 517 | { |
| 518 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 519 | PSI_FILE_CALL(register_file)(category, info, count); |
| 520 | #endif |
| 521 | } |
| 522 | |
| 523 | static inline char * |
| 524 | inline_mysql_file_fgets( |
| 525 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 526 | const char *src_file, uint src_line, |
| 527 | #endif |
| 528 | char *str, int size, MYSQL_FILE *file) |
| 529 | { |
| 530 | char *result; |
| 531 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 532 | if (psi_likely(pfs_enabled)) |
| 533 | { |
| 534 | struct PSI_file_locker *locker; |
| 535 | PSI_file_locker_state state; |
| 536 | locker= PSI_FILE_CALL(get_thread_file_stream_locker) (&state, file->m_psi, PSI_FILE_READ); |
| 537 | if (likely(locker != NULL)) |
| 538 | { |
| 539 | PSI_FILE_CALL(start_file_wait)(locker, (size_t) size, src_file, src_line); |
| 540 | result= fgets(str, size, file->m_file); |
| 541 | PSI_FILE_CALL(end_file_wait)(locker, result ? strlen(result) : 0); |
| 542 | return result; |
| 543 | } |
| 544 | } |
| 545 | #endif |
| 546 | |
| 547 | result= fgets(str, size, file->m_file); |
| 548 | return result; |
| 549 | } |
| 550 | |
| 551 | static inline int |
| 552 | inline_mysql_file_fgetc( |
| 553 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 554 | const char *src_file, uint src_line, |
| 555 | #endif |
| 556 | MYSQL_FILE *file) |
| 557 | { |
| 558 | int result; |
| 559 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 560 | if (psi_likely(pfs_enabled)) |
| 561 | { |
| 562 | struct PSI_file_locker *locker; |
| 563 | PSI_file_locker_state state; |
| 564 | locker= PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi, PSI_FILE_READ); |
| 565 | if (likely(locker != NULL)) |
| 566 | { |
| 567 | PSI_FILE_CALL(start_file_wait)(locker, (size_t) 1, src_file, src_line); |
| 568 | result= fgetc(file->m_file); |
| 569 | PSI_FILE_CALL(end_file_wait)(locker, (size_t) 1); |
| 570 | return result; |
| 571 | } |
| 572 | } |
| 573 | #endif |
| 574 | |
| 575 | result= fgetc(file->m_file); |
| 576 | return result; |
| 577 | } |
| 578 | |
| 579 | static inline int |
| 580 | inline_mysql_file_fputs( |
| 581 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 582 | const char *src_file, uint src_line, |
| 583 | #endif |
| 584 | const char *str, MYSQL_FILE *file) |
| 585 | { |
| 586 | int result; |
| 587 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 588 | if (psi_likely(pfs_enabled)) |
| 589 | { |
| 590 | struct PSI_file_locker *locker; |
| 591 | PSI_file_locker_state state; |
| 592 | size_t bytes; |
| 593 | locker= PSI_FILE_CALL(get_thread_file_stream_locker) (&state, file->m_psi, PSI_FILE_WRITE); |
| 594 | if (likely(locker != NULL)) |
| 595 | { |
| 596 | bytes= str ? strlen(str) : 0; |
| 597 | PSI_FILE_CALL(start_file_wait)(locker, bytes, src_file, src_line); |
| 598 | result= fputs(str, file->m_file); |
| 599 | PSI_FILE_CALL(end_file_wait)(locker, bytes); |
| 600 | return result; |
| 601 | } |
| 602 | } |
| 603 | #endif |
| 604 | |
| 605 | result= fputs(str, file->m_file); |
| 606 | return result; |
| 607 | } |
| 608 | |
| 609 | static inline int |
| 610 | inline_mysql_file_fputc( |
| 611 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 612 | const char *src_file, uint src_line, |
| 613 | #endif |
| 614 | char c, MYSQL_FILE *file) |
| 615 | { |
| 616 | int result; |
| 617 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 618 | if (psi_likely(pfs_enabled)) |
| 619 | { |
| 620 | struct PSI_file_locker *locker; |
| 621 | PSI_file_locker_state state; |
| 622 | locker= PSI_FILE_CALL(get_thread_file_stream_locker) (&state, file->m_psi, PSI_FILE_WRITE); |
| 623 | if (likely(locker != NULL)) |
| 624 | { |
| 625 | PSI_FILE_CALL(start_file_wait)(locker, (size_t) 1, src_file, src_line); |
| 626 | result= fputc(c, file->m_file); |
| 627 | PSI_FILE_CALL(end_file_wait)(locker, (size_t) 1); |
| 628 | return result; |
| 629 | } |
| 630 | } |
| 631 | #endif |
| 632 | |
| 633 | result= fputc(c, file->m_file); |
| 634 | return result; |
| 635 | } |
| 636 | |
| 637 | static inline int |
| 638 | inline_mysql_file_fprintf(MYSQL_FILE *file, const char *format, ...) |
| 639 | { |
| 640 | /* |
| 641 | TODO: figure out how to pass src_file and src_line from the caller. |
| 642 | */ |
| 643 | int result; |
| 644 | va_list args; |
| 645 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 646 | if (psi_likely(pfs_enabled)) |
| 647 | { |
| 648 | struct PSI_file_locker *locker; |
| 649 | PSI_file_locker_state state; |
| 650 | locker= PSI_FILE_CALL(get_thread_file_stream_locker) (&state, file->m_psi, PSI_FILE_WRITE); |
| 651 | if (likely(locker != NULL)) |
| 652 | { |
| 653 | PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, __FILE__, __LINE__); |
| 654 | va_start(args, format); |
| 655 | result= vfprintf(file->m_file, format, args); |
| 656 | va_end(args); |
| 657 | PSI_FILE_CALL(end_file_wait)(locker, (size_t) result); |
| 658 | return result; |
| 659 | } |
| 660 | } |
| 661 | #endif |
| 662 | |
| 663 | va_start(args, format); |
| 664 | result= vfprintf(file->m_file, format, args); |
| 665 | va_end(args); |
| 666 | return result; |
| 667 | } |
| 668 | |
| 669 | static inline int |
| 670 | inline_mysql_file_vfprintf( |
| 671 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 672 | const char *src_file, uint src_line, |
| 673 | #endif |
| 674 | MYSQL_FILE *file, const char *format, va_list args) |
| 675 | { |
| 676 | int result; |
| 677 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 678 | if (psi_likely(pfs_enabled)) |
| 679 | { |
| 680 | struct PSI_file_locker *locker; |
| 681 | PSI_file_locker_state state; |
| 682 | locker= PSI_FILE_CALL(get_thread_file_stream_locker) (&state, file->m_psi, PSI_FILE_WRITE); |
| 683 | if (likely(locker != NULL)) |
| 684 | { |
| 685 | PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); |
| 686 | result= vfprintf(file->m_file, format, args); |
| 687 | PSI_FILE_CALL(end_file_wait)(locker, (size_t) result); |
| 688 | return result; |
| 689 | } |
| 690 | } |
| 691 | #endif |
| 692 | |
| 693 | result= vfprintf(file->m_file, format, args); |
| 694 | return result; |
| 695 | } |
| 696 | |
| 697 | static inline int |
| 698 | inline_mysql_file_fflush( |
| 699 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 700 | const char *src_file, uint src_line, |
| 701 | #endif |
| 702 | MYSQL_FILE *file) |
| 703 | { |
| 704 | int result; |
| 705 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 706 | if (psi_likely(pfs_enabled)) |
| 707 | { |
| 708 | struct PSI_file_locker *locker; |
| 709 | PSI_file_locker_state state; |
| 710 | locker= PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi, PSI_FILE_FLUSH); |
| 711 | if (likely(locker != NULL)) |
| 712 | { |
| 713 | PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); |
| 714 | result= fflush(file->m_file); |
| 715 | PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); |
| 716 | return result; |
| 717 | } |
| 718 | } |
| 719 | #endif |
| 720 | |
| 721 | result= fflush(file->m_file); |
| 722 | return result; |
| 723 | } |
| 724 | |
| 725 | static inline int inline_mysql_file_feof(MYSQL_FILE *file) |
| 726 | { |
| 727 | /* Not instrumented, there is no wait involved */ |
| 728 | return feof(file->m_file); |
| 729 | } |
| 730 | |
| 731 | static inline int |
| 732 | inline_mysql_file_fstat( |
| 733 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 734 | const char *src_file, uint src_line, |
| 735 | #endif |
| 736 | int filenr, MY_STAT *stat_area, myf flags) |
| 737 | { |
| 738 | int result; |
| 739 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 740 | if (psi_likely(pfs_enabled)) |
| 741 | { |
| 742 | struct PSI_file_locker *locker; |
| 743 | PSI_file_locker_state state; |
| 744 | locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, filenr, PSI_FILE_FSTAT); |
| 745 | if (likely(locker != NULL)) |
| 746 | { |
| 747 | PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); |
| 748 | result= my_fstat(filenr, stat_area, flags); |
| 749 | PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); |
| 750 | return result; |
| 751 | } |
| 752 | } |
| 753 | #endif |
| 754 | |
| 755 | result= my_fstat(filenr, stat_area, flags); |
| 756 | return result; |
| 757 | } |
| 758 | |
| 759 | static inline MY_STAT * |
| 760 | inline_mysql_file_stat( |
| 761 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 762 | PSI_file_key key, const char *src_file, uint src_line, |
| 763 | #endif |
| 764 | const char *path, MY_STAT *stat_area, myf flags) |
| 765 | { |
| 766 | MY_STAT *result; |
| 767 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 768 | if (psi_likely(pfs_enabled)) |
| 769 | { |
| 770 | struct PSI_file_locker *locker; |
| 771 | PSI_file_locker_state state; |
| 772 | locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_STAT, path, &locker); |
| 773 | if (likely(locker != NULL)) |
| 774 | { |
| 775 | PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line); |
| 776 | result= my_stat(path, stat_area, flags); |
| 777 | PSI_FILE_CALL(end_file_open_wait)(locker, result); |
| 778 | return result; |
| 779 | } |
| 780 | } |
| 781 | #endif |
| 782 | |
| 783 | result= my_stat(path, stat_area, flags); |
| 784 | return result; |
| 785 | } |
| 786 | |
| 787 | static inline int |
| 788 | inline_mysql_file_chsize( |
| 789 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 790 | const char *src_file, uint src_line, |
| 791 | #endif |
| 792 | File file, my_off_t newlength, int filler, myf flags) |
| 793 | { |
| 794 | int result; |
| 795 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 796 | if (psi_likely(pfs_enabled)) |
| 797 | { |
| 798 | struct PSI_file_locker *locker; |
| 799 | PSI_file_locker_state state; |
| 800 | locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_CHSIZE); |
| 801 | if (likely(locker != NULL)) |
| 802 | { |
| 803 | PSI_FILE_CALL(start_file_wait)(locker, (size_t) newlength, src_file, |
| 804 | src_line); |
| 805 | result= my_chsize(file, newlength, filler, flags); |
| 806 | PSI_FILE_CALL(end_file_wait)(locker, (size_t) newlength); |
| 807 | return result; |
| 808 | } |
| 809 | } |
| 810 | #endif |
| 811 | |
| 812 | result= my_chsize(file, newlength, filler, flags); |
| 813 | return result; |
| 814 | } |
| 815 | |
| 816 | static inline MYSQL_FILE* |
| 817 | inline_mysql_file_fopen( |
| 818 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 819 | PSI_file_key key, const char *src_file, uint src_line, |
| 820 | #endif |
| 821 | const char *filename, int flags, myf myFlags) |
| 822 | { |
| 823 | MYSQL_FILE *that; |
| 824 | that= (MYSQL_FILE*) my_malloc(sizeof(MYSQL_FILE), MYF(MY_WME)); |
| 825 | if (likely(that != NULL)) |
| 826 | { |
| 827 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 828 | if (psi_likely(pfs_enabled)) |
| 829 | { |
| 830 | struct PSI_file_locker *locker; |
| 831 | PSI_file_locker_state state; |
| 832 | locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_STREAM_OPEN, |
| 833 | filename, that); |
| 834 | if (likely(locker != NULL)) |
| 835 | { |
| 836 | PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line); |
| 837 | that->m_file= my_fopen(filename, flags, myFlags); |
| 838 | that->m_psi= PSI_FILE_CALL(end_file_open_wait)(locker, that->m_file); |
| 839 | if (unlikely(that->m_file == NULL)) |
| 840 | { |
| 841 | my_free(that); |
| 842 | return NULL; |
| 843 | } |
| 844 | return that; |
| 845 | } |
| 846 | } |
| 847 | #endif |
| 848 | |
| 849 | that->m_psi= NULL; |
| 850 | that->m_file= my_fopen(filename, flags, myFlags); |
| 851 | if (unlikely(that->m_file == NULL)) |
| 852 | { |
| 853 | my_free(that); |
| 854 | return NULL; |
| 855 | } |
| 856 | } |
| 857 | return that; |
| 858 | } |
| 859 | |
| 860 | static inline int |
| 861 | inline_mysql_file_fclose( |
| 862 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 863 | const char *src_file, uint src_line, |
| 864 | #endif |
| 865 | MYSQL_FILE *file, myf flags) |
| 866 | { |
| 867 | int result= 0; |
| 868 | if (likely(file != NULL)) |
| 869 | { |
| 870 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 871 | if (psi_likely(pfs_enabled)) |
| 872 | { |
| 873 | struct PSI_file_locker *locker; |
| 874 | PSI_file_locker_state state; |
| 875 | locker= PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi, |
| 876 | PSI_FILE_STREAM_CLOSE); |
| 877 | if (likely(locker != NULL)) |
| 878 | { |
| 879 | PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line); |
| 880 | result= my_fclose(file->m_file, flags); |
| 881 | PSI_FILE_CALL(end_file_close_wait)(locker, result); |
| 882 | my_free(file); |
| 883 | return result; |
| 884 | } |
| 885 | } |
| 886 | #endif |
| 887 | |
| 888 | result= my_fclose(file->m_file, flags); |
| 889 | my_free(file); |
| 890 | } |
| 891 | return result; |
| 892 | } |
| 893 | |
| 894 | static inline size_t |
| 895 | inline_mysql_file_fread( |
| 896 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 897 | const char *src_file, uint src_line, |
| 898 | #endif |
| 899 | MYSQL_FILE *file, uchar *buffer, size_t count, myf flags) |
| 900 | { |
| 901 | size_t result; |
| 902 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 903 | if (psi_likely(pfs_enabled)) |
| 904 | { |
| 905 | struct PSI_file_locker *locker; |
| 906 | PSI_file_locker_state state; |
| 907 | size_t bytes_read; |
| 908 | locker= PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi, PSI_FILE_READ); |
| 909 | if (likely(locker != NULL)) |
| 910 | { |
| 911 | PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); |
| 912 | result= my_fread(file->m_file, buffer, count, flags); |
| 913 | if (flags & (MY_NABP | MY_FNABP)) |
| 914 | bytes_read= (result == 0) ? count : 0; |
| 915 | else |
| 916 | bytes_read= (result != MY_FILE_ERROR) ? result : 0; |
| 917 | PSI_FILE_CALL(end_file_wait)(locker, bytes_read); |
| 918 | return result; |
| 919 | } |
| 920 | } |
| 921 | #endif |
| 922 | |
| 923 | result= my_fread(file->m_file, buffer, count, flags); |
| 924 | return result; |
| 925 | } |
| 926 | |
| 927 | static inline size_t |
| 928 | inline_mysql_file_fwrite( |
| 929 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 930 | const char *src_file, uint src_line, |
| 931 | #endif |
| 932 | MYSQL_FILE *file, const uchar *buffer, size_t count, myf flags) |
| 933 | { |
| 934 | size_t result; |
| 935 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 936 | if (psi_likely(pfs_enabled)) |
| 937 | { |
| 938 | struct PSI_file_locker *locker; |
| 939 | PSI_file_locker_state state; |
| 940 | size_t bytes_written; |
| 941 | locker= PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi, PSI_FILE_WRITE); |
| 942 | if (likely(locker != NULL)) |
| 943 | { |
| 944 | PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); |
| 945 | result= my_fwrite(file->m_file, buffer, count, flags); |
| 946 | if (flags & (MY_NABP | MY_FNABP)) |
| 947 | bytes_written= (result == 0) ? count : 0; |
| 948 | else |
| 949 | bytes_written= (result != MY_FILE_ERROR) ? result : 0; |
| 950 | PSI_FILE_CALL(end_file_wait)(locker, bytes_written); |
| 951 | return result; |
| 952 | } |
| 953 | } |
| 954 | #endif |
| 955 | |
| 956 | result= my_fwrite(file->m_file, buffer, count, flags); |
| 957 | return result; |
| 958 | } |
| 959 | |
| 960 | static inline my_off_t |
| 961 | inline_mysql_file_fseek( |
| 962 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 963 | const char *src_file, uint src_line, |
| 964 | #endif |
| 965 | MYSQL_FILE *file, my_off_t pos, int whence, myf flags) |
| 966 | { |
| 967 | my_off_t result; |
| 968 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 969 | if (psi_likely(pfs_enabled)) |
| 970 | { |
| 971 | struct PSI_file_locker *locker; |
| 972 | PSI_file_locker_state state; |
| 973 | locker= PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi, PSI_FILE_SEEK); |
| 974 | if (likely(locker != NULL)) |
| 975 | { |
| 976 | PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); |
| 977 | result= my_fseek(file->m_file, pos, whence, flags); |
| 978 | PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); |
| 979 | return result; |
| 980 | } |
| 981 | } |
| 982 | #endif |
| 983 | |
| 984 | result= my_fseek(file->m_file, pos, whence, flags); |
| 985 | return result; |
| 986 | } |
| 987 | |
| 988 | static inline my_off_t |
| 989 | inline_mysql_file_ftell( |
| 990 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 991 | const char *src_file, uint src_line, |
| 992 | #endif |
| 993 | MYSQL_FILE *file, myf flags) |
| 994 | { |
| 995 | my_off_t result; |
| 996 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 997 | if (psi_likely(pfs_enabled)) |
| 998 | { |
| 999 | struct PSI_file_locker *locker; |
| 1000 | PSI_file_locker_state state; |
| 1001 | locker= PSI_FILE_CALL(get_thread_file_stream_locker)(&state, file->m_psi, PSI_FILE_TELL); |
| 1002 | if (likely(locker != NULL)) |
| 1003 | { |
| 1004 | PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); |
| 1005 | result= my_ftell(file->m_file, flags); |
| 1006 | PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); |
| 1007 | return result; |
| 1008 | } |
| 1009 | } |
| 1010 | #endif |
| 1011 | |
| 1012 | result= my_ftell(file->m_file, flags); |
| 1013 | return result; |
| 1014 | } |
| 1015 | |
| 1016 | static inline File |
| 1017 | inline_mysql_file_create( |
| 1018 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1019 | PSI_file_key key, const char *src_file, uint src_line, |
| 1020 | #endif |
| 1021 | const char *filename, int create_flags, int access_flags, myf myFlags) |
| 1022 | { |
| 1023 | File file; |
| 1024 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1025 | if (psi_likely(pfs_enabled)) |
| 1026 | { |
| 1027 | struct PSI_file_locker *locker; |
| 1028 | PSI_file_locker_state state; |
| 1029 | locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_CREATE, filename, |
| 1030 | &locker); |
| 1031 | if (likely(locker != NULL)) |
| 1032 | { |
| 1033 | PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line); |
| 1034 | file= my_create(filename, create_flags, access_flags, myFlags); |
| 1035 | PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file); |
| 1036 | return file; |
| 1037 | } |
| 1038 | } |
| 1039 | #endif |
| 1040 | |
| 1041 | file= my_create(filename, create_flags, access_flags, myFlags); |
| 1042 | return file; |
| 1043 | } |
| 1044 | |
| 1045 | static inline File |
| 1046 | inline_mysql_file_create_temp( |
| 1047 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1048 | PSI_file_key key, |
| 1049 | #endif |
| 1050 | char *to, const char *dir, const char *pfx, int mode, myf myFlags) |
| 1051 | { |
| 1052 | File file; |
| 1053 | /* |
| 1054 | TODO: This event is instrumented, but not timed. |
| 1055 | The problem is that the file name is now known |
| 1056 | before the create_temp_file call. |
| 1057 | */ |
| 1058 | file= create_temp_file(to, dir, pfx, mode, myFlags); |
| 1059 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1060 | PSI_FILE_CALL(create_file)(key, to, file); |
| 1061 | #endif |
| 1062 | return file; |
| 1063 | } |
| 1064 | |
| 1065 | static inline File |
| 1066 | inline_mysql_file_open( |
| 1067 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1068 | PSI_file_key key, const char *src_file, uint src_line, |
| 1069 | #endif |
| 1070 | const char *filename, int flags, myf myFlags) |
| 1071 | { |
| 1072 | File file; |
| 1073 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1074 | if (psi_likely(pfs_enabled)) |
| 1075 | { |
| 1076 | struct PSI_file_locker *locker; |
| 1077 | PSI_file_locker_state state; |
| 1078 | locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_OPEN, filename, |
| 1079 | &locker); |
| 1080 | if (likely(locker != NULL)) |
| 1081 | { |
| 1082 | PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line); |
| 1083 | file= my_open(filename, flags, myFlags); |
| 1084 | PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file); |
| 1085 | return file; |
| 1086 | } |
| 1087 | } |
| 1088 | #endif |
| 1089 | |
| 1090 | file= my_open(filename, flags, myFlags); |
| 1091 | return file; |
| 1092 | } |
| 1093 | |
| 1094 | static inline int |
| 1095 | inline_mysql_file_close( |
| 1096 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1097 | const char *src_file, uint src_line, |
| 1098 | #endif |
| 1099 | File file, myf flags) |
| 1100 | { |
| 1101 | int result; |
| 1102 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1103 | if (psi_likely(pfs_enabled)) |
| 1104 | { |
| 1105 | struct PSI_file_locker *locker; |
| 1106 | PSI_file_locker_state state; |
| 1107 | locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_CLOSE); |
| 1108 | if (likely(locker != NULL)) |
| 1109 | { |
| 1110 | PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line); |
| 1111 | result= my_close(file, flags); |
| 1112 | PSI_FILE_CALL(end_file_close_wait)(locker, result); |
| 1113 | return result; |
| 1114 | } |
| 1115 | } |
| 1116 | #endif |
| 1117 | |
| 1118 | result= my_close(file, flags); |
| 1119 | return result; |
| 1120 | } |
| 1121 | |
| 1122 | static inline size_t |
| 1123 | inline_mysql_file_read( |
| 1124 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1125 | const char *src_file, uint src_line, |
| 1126 | #endif |
| 1127 | File file, uchar *buffer, size_t count, myf flags) |
| 1128 | { |
| 1129 | size_t result; |
| 1130 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1131 | if (psi_likely(pfs_enabled)) |
| 1132 | { |
| 1133 | struct PSI_file_locker *locker; |
| 1134 | PSI_file_locker_state state; |
| 1135 | size_t bytes_read; |
| 1136 | locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_READ); |
| 1137 | if (likely(locker != NULL)) |
| 1138 | { |
| 1139 | PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); |
| 1140 | result= my_read(file, buffer, count, flags); |
| 1141 | if (flags & (MY_NABP | MY_FNABP)) |
| 1142 | bytes_read= (result == 0) ? count : 0; |
| 1143 | else |
| 1144 | bytes_read= (result != MY_FILE_ERROR) ? result : 0; |
| 1145 | PSI_FILE_CALL(end_file_wait)(locker, bytes_read); |
| 1146 | return result; |
| 1147 | } |
| 1148 | } |
| 1149 | #endif |
| 1150 | |
| 1151 | result= my_read(file, buffer, count, flags); |
| 1152 | return result; |
| 1153 | } |
| 1154 | |
| 1155 | static inline size_t |
| 1156 | inline_mysql_file_write( |
| 1157 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1158 | const char *src_file, uint src_line, |
| 1159 | #endif |
| 1160 | File file, const uchar *buffer, size_t count, myf flags) |
| 1161 | { |
| 1162 | size_t result; |
| 1163 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1164 | if (psi_likely(pfs_enabled)) |
| 1165 | { |
| 1166 | struct PSI_file_locker *locker; |
| 1167 | PSI_file_locker_state state; |
| 1168 | size_t bytes_written; |
| 1169 | locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_WRITE); |
| 1170 | if (likely(locker != NULL)) |
| 1171 | { |
| 1172 | PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); |
| 1173 | result= my_write(file, buffer, count, flags); |
| 1174 | if (flags & (MY_NABP | MY_FNABP)) |
| 1175 | bytes_written= (result == 0) ? count : 0; |
| 1176 | else |
| 1177 | bytes_written= (result != MY_FILE_ERROR) ? result : 0; |
| 1178 | PSI_FILE_CALL(end_file_wait)(locker, bytes_written); |
| 1179 | return result; |
| 1180 | } |
| 1181 | } |
| 1182 | #endif |
| 1183 | |
| 1184 | result= my_write(file, buffer, count, flags); |
| 1185 | return result; |
| 1186 | } |
| 1187 | |
| 1188 | static inline size_t |
| 1189 | inline_mysql_file_pread( |
| 1190 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1191 | const char *src_file, uint src_line, |
| 1192 | #endif |
| 1193 | File file, uchar *buffer, size_t count, my_off_t offset, myf flags) |
| 1194 | { |
| 1195 | size_t result; |
| 1196 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1197 | if (psi_likely(pfs_enabled)) |
| 1198 | { |
| 1199 | struct PSI_file_locker *locker; |
| 1200 | PSI_file_locker_state state; |
| 1201 | size_t bytes_read; |
| 1202 | locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_READ); |
| 1203 | if (likely(locker != NULL)) |
| 1204 | { |
| 1205 | PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); |
| 1206 | result= my_pread(file, buffer, count, offset, flags); |
| 1207 | if (flags & (MY_NABP | MY_FNABP)) |
| 1208 | bytes_read= (result == 0) ? count : 0; |
| 1209 | else |
| 1210 | bytes_read= (result != MY_FILE_ERROR) ? result : 0; |
| 1211 | PSI_FILE_CALL(end_file_wait)(locker, bytes_read); |
| 1212 | return result; |
| 1213 | } |
| 1214 | } |
| 1215 | #endif |
| 1216 | |
| 1217 | result= my_pread(file, buffer, count, offset, flags); |
| 1218 | return result; |
| 1219 | } |
| 1220 | |
| 1221 | static inline size_t |
| 1222 | inline_mysql_file_pwrite( |
| 1223 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1224 | const char *src_file, uint src_line, |
| 1225 | #endif |
| 1226 | File file, const uchar *buffer, size_t count, my_off_t offset, myf flags) |
| 1227 | { |
| 1228 | size_t result; |
| 1229 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1230 | if (psi_likely(pfs_enabled)) |
| 1231 | { |
| 1232 | struct PSI_file_locker *locker; |
| 1233 | PSI_file_locker_state state; |
| 1234 | size_t bytes_written; |
| 1235 | locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_WRITE); |
| 1236 | if (likely(locker != NULL)) |
| 1237 | { |
| 1238 | PSI_FILE_CALL(start_file_wait)(locker, count, src_file, src_line); |
| 1239 | result= my_pwrite(file, buffer, count, offset, flags); |
| 1240 | if (flags & (MY_NABP | MY_FNABP)) |
| 1241 | bytes_written= (result == 0) ? count : 0; |
| 1242 | else |
| 1243 | bytes_written= (result != MY_FILE_ERROR) ? result : 0; |
| 1244 | PSI_FILE_CALL(end_file_wait)(locker, bytes_written); |
| 1245 | return result; |
| 1246 | } |
| 1247 | } |
| 1248 | #endif |
| 1249 | |
| 1250 | result= my_pwrite(file, buffer, count, offset, flags); |
| 1251 | return result; |
| 1252 | } |
| 1253 | |
| 1254 | static inline my_off_t |
| 1255 | inline_mysql_file_seek( |
| 1256 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1257 | const char *src_file, uint src_line, |
| 1258 | #endif |
| 1259 | File file, my_off_t pos, int whence, myf flags) |
| 1260 | { |
| 1261 | my_off_t result; |
| 1262 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1263 | if (psi_likely(pfs_enabled)) |
| 1264 | { |
| 1265 | struct PSI_file_locker *locker; |
| 1266 | PSI_file_locker_state state; |
| 1267 | locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_SEEK); |
| 1268 | if (likely(locker != NULL)) |
| 1269 | { |
| 1270 | PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); |
| 1271 | result= my_seek(file, pos, whence, flags); |
| 1272 | PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); |
| 1273 | return result; |
| 1274 | } |
| 1275 | } |
| 1276 | #endif |
| 1277 | |
| 1278 | result= my_seek(file, pos, whence, flags); |
| 1279 | return result; |
| 1280 | } |
| 1281 | |
| 1282 | static inline my_off_t |
| 1283 | inline_mysql_file_tell( |
| 1284 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1285 | const char *src_file, uint src_line, |
| 1286 | #endif |
| 1287 | File file, myf flags) |
| 1288 | { |
| 1289 | my_off_t result; |
| 1290 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1291 | if (psi_likely(pfs_enabled)) |
| 1292 | { |
| 1293 | struct PSI_file_locker *locker; |
| 1294 | PSI_file_locker_state state; |
| 1295 | locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, file, PSI_FILE_TELL); |
| 1296 | if (likely(locker != NULL)) |
| 1297 | { |
| 1298 | PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); |
| 1299 | result= my_tell(file, flags); |
| 1300 | PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); |
| 1301 | return result; |
| 1302 | } |
| 1303 | } |
| 1304 | #endif |
| 1305 | |
| 1306 | result= my_tell(file, flags); |
| 1307 | return result; |
| 1308 | } |
| 1309 | |
| 1310 | static inline int |
| 1311 | inline_mysql_file_delete( |
| 1312 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1313 | PSI_file_key key, const char *src_file, uint src_line, |
| 1314 | #endif |
| 1315 | const char *name, myf flags) |
| 1316 | { |
| 1317 | int result; |
| 1318 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1319 | if (psi_likely(pfs_enabled)) |
| 1320 | { |
| 1321 | struct PSI_file_locker *locker; |
| 1322 | PSI_file_locker_state state; |
| 1323 | locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_DELETE, name, &locker); |
| 1324 | if (likely(locker != NULL)) |
| 1325 | { |
| 1326 | PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line); |
| 1327 | result= my_delete(name, flags); |
| 1328 | PSI_FILE_CALL(end_file_close_wait)(locker, result); |
| 1329 | return result; |
| 1330 | } |
| 1331 | } |
| 1332 | #endif |
| 1333 | |
| 1334 | result= my_delete(name, flags); |
| 1335 | return result; |
| 1336 | } |
| 1337 | |
| 1338 | static inline int |
| 1339 | inline_mysql_file_rename( |
| 1340 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1341 | PSI_file_key key, const char *src_file, uint src_line, |
| 1342 | #endif |
| 1343 | const char *from, const char *to, myf flags) |
| 1344 | { |
| 1345 | int result; |
| 1346 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1347 | if (psi_likely(pfs_enabled)) |
| 1348 | { |
| 1349 | struct PSI_file_locker *locker; |
| 1350 | PSI_file_locker_state state; |
| 1351 | locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_RENAME, to, &locker); |
| 1352 | if (likely(locker != NULL)) |
| 1353 | { |
| 1354 | PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); |
| 1355 | result= my_rename(from, to, flags); |
| 1356 | PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); |
| 1357 | return result; |
| 1358 | } |
| 1359 | } |
| 1360 | #endif |
| 1361 | |
| 1362 | result= my_rename(from, to, flags); |
| 1363 | return result; |
| 1364 | } |
| 1365 | |
| 1366 | |
| 1367 | static inline File |
| 1368 | inline_mysql_file_create_with_symlink( |
| 1369 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1370 | PSI_file_key key, const char *src_file, uint src_line, |
| 1371 | #endif |
| 1372 | const char *linkname, const char *filename, int create_flags, |
| 1373 | int access_flags, myf flags) |
| 1374 | { |
| 1375 | File file; |
| 1376 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1377 | if (psi_likely(pfs_enabled)) |
| 1378 | { |
| 1379 | struct PSI_file_locker *locker; |
| 1380 | PSI_file_locker_state state; |
| 1381 | locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_CREATE, filename, |
| 1382 | &locker); |
| 1383 | if (likely(locker != NULL)) |
| 1384 | { |
| 1385 | PSI_FILE_CALL(start_file_open_wait)(locker, src_file, src_line); |
| 1386 | file= my_create_with_symlink(linkname, filename, create_flags, access_flags, |
| 1387 | flags); |
| 1388 | PSI_FILE_CALL(end_file_open_wait_and_bind_to_descriptor)(locker, file); |
| 1389 | return file; |
| 1390 | } |
| 1391 | } |
| 1392 | #endif |
| 1393 | |
| 1394 | file= my_create_with_symlink(linkname, filename, create_flags, access_flags, |
| 1395 | flags); |
| 1396 | return file; |
| 1397 | } |
| 1398 | |
| 1399 | |
| 1400 | static inline int |
| 1401 | inline_mysql_file_delete_with_symlink( |
| 1402 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1403 | PSI_file_key key, const char *src_file, uint src_line, |
| 1404 | #endif |
| 1405 | const char *name, const char *ext, myf flags) |
| 1406 | { |
| 1407 | int result; |
| 1408 | char buf[FN_REFLEN]; |
| 1409 | char *fullname= fn_format(buf, name, "" , ext, MY_UNPACK_FILENAME | MY_APPEND_EXT); |
| 1410 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1411 | if (psi_likely(pfs_enabled)) |
| 1412 | { |
| 1413 | struct PSI_file_locker *locker; |
| 1414 | PSI_file_locker_state state; |
| 1415 | locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_DELETE, fullname, |
| 1416 | &locker); |
| 1417 | if (likely(locker != NULL)) |
| 1418 | { |
| 1419 | PSI_FILE_CALL(start_file_close_wait)(locker, src_file, src_line); |
| 1420 | result= my_handler_delete_with_symlink(fullname, flags); |
| 1421 | PSI_FILE_CALL(end_file_close_wait)(locker, result); |
| 1422 | return result; |
| 1423 | } |
| 1424 | } |
| 1425 | #endif |
| 1426 | |
| 1427 | result= my_handler_delete_with_symlink(fullname, flags); |
| 1428 | return result; |
| 1429 | } |
| 1430 | |
| 1431 | |
| 1432 | static inline int |
| 1433 | inline_mysql_file_rename_with_symlink( |
| 1434 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1435 | PSI_file_key key, const char *src_file, uint src_line, |
| 1436 | #endif |
| 1437 | const char *from, const char *to, myf flags) |
| 1438 | { |
| 1439 | int result; |
| 1440 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1441 | if (psi_likely(pfs_enabled)) |
| 1442 | { |
| 1443 | struct PSI_file_locker *locker; |
| 1444 | PSI_file_locker_state state; |
| 1445 | locker= PSI_FILE_CALL(get_thread_file_name_locker)(&state, key, PSI_FILE_RENAME, to, &locker); |
| 1446 | if (likely(locker != NULL)) |
| 1447 | { |
| 1448 | PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); |
| 1449 | result= my_rename_with_symlink(from, to, flags); |
| 1450 | PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); |
| 1451 | return result; |
| 1452 | } |
| 1453 | } |
| 1454 | #endif |
| 1455 | |
| 1456 | result= my_rename_with_symlink(from, to, flags); |
| 1457 | return result; |
| 1458 | } |
| 1459 | |
| 1460 | static inline int |
| 1461 | inline_mysql_file_sync( |
| 1462 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1463 | const char *src_file, uint src_line, |
| 1464 | #endif |
| 1465 | File fd, myf flags) |
| 1466 | { |
| 1467 | int result= 0; |
| 1468 | #ifdef HAVE_PSI_FILE_INTERFACE |
| 1469 | if (psi_likely(pfs_enabled)) |
| 1470 | { |
| 1471 | struct PSI_file_locker *locker; |
| 1472 | PSI_file_locker_state state; |
| 1473 | locker= PSI_FILE_CALL(get_thread_file_descriptor_locker)(&state, fd, PSI_FILE_SYNC); |
| 1474 | if (likely(locker != NULL)) |
| 1475 | { |
| 1476 | PSI_FILE_CALL(start_file_wait)(locker, (size_t) 0, src_file, src_line); |
| 1477 | result= my_sync(fd, flags); |
| 1478 | PSI_FILE_CALL(end_file_wait)(locker, (size_t) 0); |
| 1479 | return result; |
| 1480 | } |
| 1481 | } |
| 1482 | #endif |
| 1483 | |
| 1484 | result= my_sync(fd, flags); |
| 1485 | return result; |
| 1486 | } |
| 1487 | |
| 1488 | /** @} (end of group File_instrumentation) */ |
| 1489 | |
| 1490 | #endif |
| 1491 | |