mysql_file.h 38 KB

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