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;
59
/* register a file open or creation depending on "create_mode" */
60
register_pfs_file_open_begin(locker, key,
61
((create_mode == OS_FILE_CREATE)
64
name, src_file, src_line);
66
file = os_file_create_simple_func(name, create_mode,
67
access_type, success);
69
/* Regsiter the returning "file" value with the system */
70
register_pfs_file_open_end(locker, file);
75
/****************************************************************//**
76
NOTE! Please use the corresponding macro
77
os_file_create_simple_no_error_handling(), not directly this function!
78
A performance schema instrumented wrapper function for
79
os_file_create_simple_no_error_handling(). Add instrumentation to
80
monitor file creation/open.
81
@return own: handle to the file, not defined if error, error number
82
can be retrieved with os_file_get_last_error */
85
pfs_os_file_create_simple_no_error_handling_func(
86
/*=============================================*/
87
mysql_pfs_key_t key, /*!< in: Performance Schema Key */
88
const char* name, /*!< in: name of the file or path as a
89
null-terminated string */
90
ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
91
is opened (if does not exist, error), or
92
OS_FILE_CREATE if a new file is created
94
ulint access_type,/*!< in: OS_FILE_READ_ONLY,
95
OS_FILE_READ_WRITE, or
96
OS_FILE_READ_ALLOW_DELETE; the last option is
97
used by a backup program reading the file */
98
ibool* success,/*!< out: TRUE if succeed, FALSE if error */
99
const char* src_file,/*!< in: file name where func invoked */
100
ulint src_line)/*!< in: line where the func invoked */
103
struct PSI_file_locker* locker = NULL;
105
/* register a file open or creation depending on "create_mode" */
106
register_pfs_file_open_begin(locker, key,
107
((create_mode == OS_FILE_CREATE)
110
name, src_file, src_line);
112
file = os_file_create_simple_no_error_handling_func(
113
name, create_mode, access_type, success);
115
register_pfs_file_open_end(locker, file);
120
/****************************************************************//**
121
NOTE! Please use the corresponding macro os_file_create(), not directly
123
A performance schema wrapper function for os_file_create().
124
Add instrumentation to monitor file creation/open.
125
@return own: handle to the file, not defined if error, error number
126
can be retrieved with os_file_get_last_error */
129
pfs_os_file_create_func(
130
/*====================*/
131
mysql_pfs_key_t key, /*!< in: Performance Schema Key */
132
const char* name, /*!< in: name of the file or path as a
133
null-terminated string */
134
ulint create_mode,/*!< in: OS_FILE_OPEN if an existing file
135
is opened (if does not exist, error), or
136
OS_FILE_CREATE if a new file is created
138
OS_FILE_OVERWRITE if a new file is created
139
or an old overwritten;
140
OS_FILE_OPEN_RAW, if a raw device or disk
141
partition should be opened */
142
ulint purpose,/*!< in: OS_FILE_AIO, if asynchronous,
143
non-buffered i/o is desired,
144
OS_FILE_NORMAL, if any normal file;
145
NOTE that it also depends on type, os_aio_..
146
and srv_.. variables whether we really use
147
async i/o or unbuffered i/o: look in the
148
function source code for the exact rules */
149
ulint type, /*!< in: OS_DATA_FILE or OS_LOG_FILE */
150
ibool* success,/*!< out: TRUE if succeed, FALSE if error */
151
const char* src_file,/*!< in: file name where func invoked */
152
ulint src_line)/*!< in: line where the func invoked */
155
struct PSI_file_locker* locker = NULL;
157
/* register a file open or creation depending on "create_mode" */
158
register_pfs_file_open_begin(locker, key,
159
((create_mode == OS_FILE_CREATE)
162
name, src_file, src_line);
164
file = os_file_create_func(name, create_mode, purpose, type, success);
166
register_pfs_file_open_end(locker, file);
171
/***********************************************************************//**
172
NOTE! Please use the corresponding macro os_file_close(), not directly
174
A performance schema instrumented wrapper function for os_file_close().
175
@return TRUE if success */
178
pfs_os_file_close_func(
179
/*===================*/
180
os_file_t file, /*!< in, own: handle to a file */
181
const char* src_file,/*!< in: file name where func invoked */
182
ulint src_line)/*!< in: line where the func invoked */
185
struct PSI_file_locker* locker = NULL;
187
/* register the file close */
188
register_pfs_file_io_begin(locker, file, 0, PSI_FILE_CLOSE,
191
result = os_file_close_func(file);
193
register_pfs_file_io_end(locker, 0);
198
/*******************************************************************//**
199
NOTE! Please use the corresponding macro os_aio(), not directly this
201
Performance schema instrumented wrapper function of os_aio() which
202
requests an asynchronous i/o operation.
203
@return TRUE if request was queued successfully, FALSE if fail */
208
ulint type, /*!< in: OS_FILE_READ or OS_FILE_WRITE */
209
ulint mode, /*!< in: OS_AIO_NORMAL etc. I/O mode */
210
const char* name, /*!< in: name of the file or path as a
211
null-terminated string */
212
os_file_t file, /*!< in: handle to a file */
213
void* buf, /*!< in: buffer where to read or from which
215
ulint offset, /*!< in: least significant 32 bits of file
216
offset where to read or write */
217
ulint offset_high,/*!< in: most significant 32 bits of
219
ulint n, /*!< in: number of bytes to read or write */
220
fil_node_t* message1,/*!< in: message for the aio handler
221
(can be used to identify a completed
222
aio operation); ignored if mode is
224
void* message2,/*!< in: message for the aio handler
225
(can be used to identify a completed
226
aio operation); ignored if mode is
228
const char* src_file,/*!< in: file name where func invoked */
229
ulint src_line)/*!< in: line where the func invoked */
232
struct PSI_file_locker* locker = NULL;
234
/* Register the read or write I/O depending on "type" */
235
register_pfs_file_io_begin(locker, file, n,
236
(type == OS_FILE_WRITE)
241
result = os_aio_func(type, mode, name, file, buf, offset, offset_high,
242
n, message1, message2);
244
register_pfs_file_io_end(locker, n);
249
/*******************************************************************//**
250
NOTE! Please use the corresponding macro os_file_read(), not directly
252
This is the performance schema instrumented wrapper function for
253
os_file_read() which requests a synchronous read operation.
254
@return TRUE if request was successful, FALSE if fail */
257
pfs_os_file_read_func(
258
/*==================*/
259
os_file_t file, /*!< in: handle to a file */
260
void* buf, /*!< in: buffer where to read */
261
ulint offset, /*!< in: least significant 32 bits of file
262
offset where to read */
263
ulint offset_high,/*!< in: most significant 32 bits of
265
ulint n, /*!< in: number of bytes to read */
266
const char* src_file,/*!< in: file name where func invoked */
267
ulint src_line)/*!< in: line where the func invoked */
270
struct PSI_file_locker* locker = NULL;
272
register_pfs_file_io_begin(locker, file, n, PSI_FILE_READ,
275
result = os_file_read_func(file, buf, offset, offset_high, n);
277
register_pfs_file_io_end(locker, n);
282
/*******************************************************************//**
283
NOTE! Please use the corresponding macro
284
os_file_read_no_error_handling(), not directly this function!
285
This is the performance schema instrumented wrapper function for
286
os_file_read_no_error_handling() which requests a synchronous
287
positioned read operation. This function does not do any error
288
handling. In case of error it returns FALSE.
289
@return TRUE if request was successful, FALSE if fail */
292
pfs_os_file_read_no_error_handling_func(
293
/*====================================*/
294
os_file_t file, /*!< in: handle to a file */
295
void* buf, /*!< in: buffer where to read */
296
ulint offset, /*!< in: least significant 32 bits of file
297
offset where to read */
298
ulint offset_high,/*!< in: most significant 32 bits of
300
ulint n, /*!< in: number of bytes to read */
301
const char* src_file,/*!< in: file name where func invoked */
302
ulint src_line)/*!< in: line where the func invoked */
305
struct PSI_file_locker* locker = NULL;
307
register_pfs_file_io_begin(locker, file, n, PSI_FILE_READ,
310
result = os_file_read_no_error_handling_func(file, buf, offset,
313
register_pfs_file_io_end(locker, n);
318
/*******************************************************************//**
319
NOTE! Please use the corresponding macro os_file_write(), not directly
321
This is the performance schema instrumented wrapper function for
322
os_file_write() which requests a synchronous write operation.
323
@return TRUE if request was successful, FALSE if fail */
326
pfs_os_file_write_func(
327
/*===================*/
328
const char* name, /*!< in: name of the file or path as a
329
null-terminated string */
330
os_file_t file, /*!< in: handle to a file */
331
const void* buf, /*!< in: buffer from which to write */
332
ulint offset, /*!< in: least significant 32 bits of file
333
offset where to write */
334
ulint offset_high,/*!< in: most significant 32 bits of
336
ulint n, /*!< in: number of bytes to write */
337
const char* src_file,/*!< in: file name where func invoked */
338
ulint src_line)/*!< in: line where the func invoked */
341
struct PSI_file_locker* locker = NULL;
343
register_pfs_file_io_begin(locker, file, n, PSI_FILE_WRITE,
346
result = os_file_write_func(name, file, buf, offset, offset_high, n);
348
register_pfs_file_io_end(locker, n);
353
/***********************************************************************//**
354
NOTE! Please use the corresponding macro os_file_flush(), not directly
356
This is the performance schema instrumented wrapper function for
357
os_file_flush() which flushes the write buffers of a given file to the disk.
358
@return TRUE if success */
361
pfs_os_file_flush_func(
362
/*===================*/
363
os_file_t file, /*!< in, own: handle to a file */
364
const char* src_file,/*!< in: file name where func invoked */
365
ulint src_line)/*!< in: line where the func invoked */
368
struct PSI_file_locker* locker = NULL;
370
register_pfs_file_io_begin(locker, file, 0, PSI_FILE_SYNC,
372
result = os_file_flush_func(file);
374
register_pfs_file_io_end(locker, 0);
379
/***********************************************************************//**
380
NOTE! Please use the corresponding macro os_file_rename(), not directly
382
This is the performance schema instrumented wrapper function for
384
@return TRUE if success */
387
pfs_os_file_rename_func(
388
/*====================*/
389
mysql_pfs_key_t key, /*!< in: Performance Schema Key */
390
const char* oldpath,/*!< in: old file path as a null-terminated
392
const char* newpath,/*!< in: new file path */
393
const char* src_file,/*!< in: file name where func invoked */
394
ulint src_line)/*!< in: line where the func invoked */
397
struct PSI_file_locker* locker = NULL;
399
register_pfs_file_open_begin(locker, key, PSI_FILE_RENAME, newpath,
402
result = os_file_rename_func(oldpath, newpath);
404
register_pfs_file_open_end(locker, 0);
408
#endif /* UNIV_PFS_IO */