1
/*****************************************************************************
3
Copyright (C) 2010, Oracle and/or its affiliates. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/os0file.ic
21
The interface to the operating system file io
23
Created 2/20/2010 Jimmy Yang
24
*******************************************************/
29
/****************************************************************//**
30
NOTE! Please use the corresponding macro os_file_create_simple(),
31
not directly this function!
32
A performance schema instrumented wrapper function for
33
os_file_create_simple() which opens or creates a file.
34
@return own: handle to the file, not defined if error, error number
35
can be retrieved with os_file_get_last_error */
38
pfs_os_file_create_simple_func(
39
/*===========================*/
40
mysql_pfs_key_t key, /*!< in: Performance Schema Key */
41
const char* name, /*!< in: name of the file or path as a
42
null-terminated string */
43
ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file is
44
opened (if does not exist, error), or
45
OS_FILE_CREATE if a new file is created
46
(if exists, error), or
47
OS_FILE_CREATE_PATH if new file
48
(if exists, error) and subdirectories along
49
its path are created (if needed)*/
50
ulint access_type,/*!< in: OS_FILE_READ_ONLY or
52
ibool* success,/*!< out: TRUE if succeed, FALSE if error */
53
const char* src_file,/*!< in: file name where func invoked */
54
ulint src_line)/*!< in: line where the func invoked */
57
struct PSI_file_locker* locker = NULL;
58
PSI_file_locker_state state;
60
/* register a file open or creation depending on "create_mode" */
61
register_pfs_file_open_begin(&state, locker, key,
62
((create_mode == OS_FILE_CREATE)
65
name, src_file, src_line);
67
file = os_file_create_simple_func(name, create_mode,
68
access_type, success);
70
/* Regsiter the returning "file" value with the system */
71
register_pfs_file_open_end(locker, file);
76
/****************************************************************//**
77
NOTE! Please use the corresponding macro
78
os_file_create_simple_no_error_handling(), not directly this function!
79
A performance schema instrumented wrapper function for
80
os_file_create_simple_no_error_handling(). Add instrumentation to
81
monitor file creation/open.
82
@return own: handle to the file, not defined if error, error number
83
can be retrieved with os_file_get_last_error */
86
pfs_os_file_create_simple_no_error_handling_func(
87
/*=============================================*/
88
mysql_pfs_key_t key, /*!< in: Performance Schema Key */
89
const char* name, /*!< in: name of the file or path as a
90
null-terminated string */
91
ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
92
is opened (if does not exist, error), or
93
OS_FILE_CREATE if a new file is created
95
ulint access_type,/*!< in: OS_FILE_READ_ONLY,
96
OS_FILE_READ_WRITE, or
97
OS_FILE_READ_ALLOW_DELETE; the last option is
98
used by a backup program reading the file */
99
ibool* success,/*!< out: TRUE if succeed, FALSE if error */
100
const char* src_file,/*!< in: file name where func invoked */
101
ulint src_line)/*!< in: line where the func invoked */
104
struct PSI_file_locker* locker = NULL;
105
PSI_file_locker_state state;
107
/* register a file open or creation depending on "create_mode" */
108
register_pfs_file_open_begin(&state, locker, key,
109
((create_mode == OS_FILE_CREATE)
112
name, src_file, src_line);
114
file = os_file_create_simple_no_error_handling_func(
115
name, create_mode, access_type, success);
117
register_pfs_file_open_end(locker, file);
122
/****************************************************************//**
123
NOTE! Please use the corresponding macro os_file_create(), not directly
125
A performance schema wrapper function for os_file_create().
126
Add instrumentation to monitor file creation/open.
127
@return own: handle to the file, not defined if error, error number
128
can be retrieved with os_file_get_last_error */
131
pfs_os_file_create_func(
132
/*====================*/
133
mysql_pfs_key_t key, /*!< in: Performance Schema Key */
134
const char* name, /*!< in: name of the file or path as a
135
null-terminated string */
136
ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
137
is opened (if does not exist, error), or
138
OS_FILE_CREATE if a new file is created
140
OS_FILE_OVERWRITE if a new file is created
141
or an old overwritten;
142
OS_FILE_OPEN_RAW, if a raw device or disk
143
partition should be opened */
144
ulint purpose,/*!< in: OS_FILE_AIO, if asynchronous,
145
non-buffered i/o is desired,
146
OS_FILE_NORMAL, if any normal file;
147
NOTE that it also depends on type, os_aio_..
148
and srv_.. variables whether we really use
149
async i/o or unbuffered i/o: look in the
150
function source code for the exact rules */
151
ulint type, /*!< in: OS_DATA_FILE or OS_LOG_FILE */
152
ibool* success,/*!< out: TRUE if succeed, FALSE if error */
153
const char* src_file,/*!< in: file name where func invoked */
154
ulint src_line)/*!< in: line where the func invoked */
157
struct PSI_file_locker* locker = NULL;
158
PSI_file_locker_state state;
160
/* register a file open or creation depending on "create_mode" */
161
register_pfs_file_open_begin(&state, locker, key,
162
((create_mode == OS_FILE_CREATE)
165
name, src_file, src_line);
167
file = os_file_create_func(name, create_mode, purpose, type, success);
169
register_pfs_file_open_end(locker, file);
174
/***********************************************************************//**
175
NOTE! Please use the corresponding macro os_file_close(), not directly
177
A performance schema instrumented wrapper function for os_file_close().
178
@return TRUE if success */
181
pfs_os_file_close_func(
182
/*===================*/
183
os_file_t file, /*!< in, own: handle to a file */
184
const char* src_file,/*!< in: file name where func invoked */
185
ulint src_line)/*!< in: line where the func invoked */
188
struct PSI_file_locker* locker = NULL;
189
PSI_file_locker_state state;
191
/* register the file close */
192
register_pfs_file_io_begin(&state, locker, file, 0, PSI_FILE_CLOSE,
195
result = os_file_close_func(file);
197
register_pfs_file_io_end(locker, 0);
202
/*******************************************************************//**
203
NOTE! Please use the corresponding macro os_aio(), not directly this
205
Performance schema instrumented wrapper function of os_aio() which
206
requests an asynchronous i/o operation.
207
@return TRUE if request was queued successfully, FALSE if fail */
212
ulint type, /*!< in: OS_FILE_READ or OS_FILE_WRITE */
213
ulint mode, /*!< in: OS_AIO_NORMAL etc. I/O mode */
214
const char* name, /*!< in: name of the file or path as a
215
null-terminated string */
216
os_file_t file, /*!< in: handle to a file */
217
void* buf, /*!< in: buffer where to read or from which
219
ulint offset, /*!< in: least significant 32 bits of file
220
offset where to read or write */
221
ulint offset_high,/*!< in: most significant 32 bits of
223
ulint n, /*!< in: number of bytes to read or write */
224
fil_node_t* message1,/*!< in: message for the aio handler
225
(can be used to identify a completed
226
aio operation); ignored if mode is
228
void* message2,/*!< in: message for the aio handler
229
(can be used to identify a completed
230
aio operation); ignored if mode is
232
const char* src_file,/*!< in: file name where func invoked */
233
ulint src_line)/*!< in: line where the func invoked */
236
struct PSI_file_locker* locker = NULL;
237
PSI_file_locker_state state;
239
/* Register the read or write I/O depending on "type" */
240
register_pfs_file_io_begin(&state, locker, file, n,
241
(type == OS_FILE_WRITE)
246
result = os_aio_func(type, mode, name, file, buf, offset, offset_high,
247
n, message1, message2);
249
register_pfs_file_io_end(locker, n);
254
/*******************************************************************//**
255
NOTE! Please use the corresponding macro os_file_read(), not directly
257
This is the performance schema instrumented wrapper function for
258
os_file_read() which requests a synchronous read operation.
259
@return TRUE if request was successful, FALSE if fail */
262
pfs_os_file_read_func(
263
/*==================*/
264
os_file_t file, /*!< in: handle to a file */
265
void* buf, /*!< in: buffer where to read */
266
ulint offset, /*!< in: least significant 32 bits of file
267
offset where to read */
268
ulint offset_high,/*!< in: most significant 32 bits of
270
ulint n, /*!< in: number of bytes to read */
271
const char* src_file,/*!< in: file name where func invoked */
272
ulint src_line)/*!< in: line where the func invoked */
275
struct PSI_file_locker* locker = NULL;
276
PSI_file_locker_state state;
278
register_pfs_file_io_begin(&state, locker, file, n, PSI_FILE_READ,
281
result = os_file_read_func(file, buf, offset, offset_high, n);
283
register_pfs_file_io_end(locker, n);
288
/*******************************************************************//**
289
NOTE! Please use the corresponding macro
290
os_file_read_no_error_handling(), not directly this function!
291
This is the performance schema instrumented wrapper function for
292
os_file_read_no_error_handling() which requests a synchronous
293
positioned read operation. This function does not do any error
294
handling. In case of error it returns FALSE.
295
@return TRUE if request was successful, FALSE if fail */
298
pfs_os_file_read_no_error_handling_func(
299
/*====================================*/
300
os_file_t file, /*!< in: handle to a file */
301
void* buf, /*!< in: buffer where to read */
302
ulint offset, /*!< in: least significant 32 bits of file
303
offset where to read */
304
ulint offset_high,/*!< in: most significant 32 bits of
306
ulint n, /*!< in: number of bytes to read */
307
const char* src_file,/*!< in: file name where func invoked */
308
ulint src_line)/*!< in: line where the func invoked */
311
struct PSI_file_locker* locker = NULL;
312
PSI_file_locker_state state;
314
register_pfs_file_io_begin(&state, locker, file, n, PSI_FILE_READ,
317
result = os_file_read_no_error_handling_func(file, buf, offset,
320
register_pfs_file_io_end(locker, n);
325
/*******************************************************************//**
326
NOTE! Please use the corresponding macro os_file_write(), not directly
328
This is the performance schema instrumented wrapper function for
329
os_file_write() which requests a synchronous write operation.
330
@return TRUE if request was successful, FALSE if fail */
333
pfs_os_file_write_func(
334
/*===================*/
335
const char* name, /*!< in: name of the file or path as a
336
null-terminated string */
337
os_file_t file, /*!< in: handle to a file */
338
const void* buf, /*!< in: buffer from which to write */
339
ulint offset, /*!< in: least significant 32 bits of file
340
offset where to write */
341
ulint offset_high,/*!< in: most significant 32 bits of
343
ulint n, /*!< in: number of bytes to write */
344
const char* src_file,/*!< in: file name where func invoked */
345
ulint src_line)/*!< in: line where the func invoked */
348
struct PSI_file_locker* locker = NULL;
349
PSI_file_locker_state state;
351
register_pfs_file_io_begin(&state, locker, file, n, PSI_FILE_WRITE,
354
result = os_file_write_func(name, file, buf, offset, offset_high, n);
356
register_pfs_file_io_end(locker, n);
361
/***********************************************************************//**
362
NOTE! Please use the corresponding macro os_file_flush(), not directly
364
This is the performance schema instrumented wrapper function for
365
os_file_flush() which flushes the write buffers of a given file to the disk.
366
@return TRUE if success */
369
pfs_os_file_flush_func(
370
/*===================*/
371
os_file_t file, /*!< in, own: handle to a file */
372
const char* src_file,/*!< in: file name where func invoked */
373
ulint src_line)/*!< in: line where the func invoked */
376
struct PSI_file_locker* locker = NULL;
377
PSI_file_locker_state state;
379
register_pfs_file_io_begin(&state, locker, file, 0, PSI_FILE_SYNC,
381
result = os_file_flush_func(file);
383
register_pfs_file_io_end(locker, 0);
388
/***********************************************************************//**
389
NOTE! Please use the corresponding macro os_file_rename(), not directly
391
This is the performance schema instrumented wrapper function for
393
@return TRUE if success */
396
pfs_os_file_rename_func(
397
/*====================*/
398
mysql_pfs_key_t key, /*!< in: Performance Schema Key */
399
const char* oldpath,/*!< in: old file path as a null-terminated
401
const char* newpath,/*!< in: new file path */
402
const char* src_file,/*!< in: file name where func invoked */
403
ulint src_line)/*!< in: line where the func invoked */
406
struct PSI_file_locker* locker = NULL;
407
PSI_file_locker_state state;
409
register_pfs_file_open_begin(&state, locker, key, PSI_FILE_RENAME, newpath,
412
result = os_file_rename_func(oldpath, newpath);
414
register_pfs_file_open_end(locker, 0);
418
#endif /* UNIV_PFS_IO */