mysql_file.h 39 KB

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