~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/os0file.ic

  • Committer: Patrick Crews
  • Date: 2011-01-29 14:17:35 UTC
  • mto: (2126.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2127.
  • Revision ID: gleebix@gmail.com-20110129141735-3y2658vt5ur0a33o
Fixes to make test-dbqp

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 
 
3
Copyright (C) 2010, Oracle and/or its affiliates. All Rights Reserved.
 
4
 
 
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.
 
8
 
 
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.
 
12
 
 
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
 
16
 
 
17
*****************************************************************************/
 
18
 
 
19
/**************************************************//**
 
20
@file include/os0file.ic
 
21
The interface to the operating system file io
 
22
 
 
23
Created 2/20/2010 Jimmy Yang
 
24
*******************************************************/
 
25
 
 
26
#include "univ.i"
 
27
 
 
28
#ifdef UNIV_PFS_IO
 
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 */
 
36
UNIV_INLINE
 
37
os_file_t
 
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
 
51
                                OS_FILE_READ_WRITE */
 
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 */
 
55
{
 
56
        os_file_t       file;
 
57
        struct PSI_file_locker* locker = NULL;
 
58
        PSI_file_locker_state   state;
 
59
 
 
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)
 
63
                                        ? PSI_FILE_CREATE
 
64
                                        : PSI_FILE_OPEN),
 
65
                                     name, src_file, src_line);
 
66
 
 
67
        file = os_file_create_simple_func(name, create_mode,
 
68
                                          access_type, success);
 
69
 
 
70
        /* Regsiter the returning "file" value with the system */
 
71
        register_pfs_file_open_end(locker, file);
 
72
 
 
73
        return(file);
 
74
}
 
75
 
 
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 */
 
84
UNIV_INLINE
 
85
os_file_t
 
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
 
94
                                (if exists, error) */
 
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 */
 
102
{
 
103
        os_file_t       file;
 
104
        struct PSI_file_locker* locker = NULL;
 
105
        PSI_file_locker_state   state;
 
106
 
 
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)
 
110
                                        ? PSI_FILE_CREATE
 
111
                                        : PSI_FILE_OPEN),
 
112
                                     name, src_file, src_line);
 
113
 
 
114
        file = os_file_create_simple_no_error_handling_func(
 
115
                name, create_mode, access_type, success);
 
116
 
 
117
        register_pfs_file_open_end(locker, file);
 
118
 
 
119
        return(file);
 
120
}
 
121
 
 
122
/****************************************************************//**
 
123
NOTE! Please use the corresponding macro os_file_create(), not directly
 
124
this function!
 
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 */
 
129
UNIV_INLINE
 
130
os_file_t
 
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
 
139
                                (if exists, error),
 
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 */
 
155
{
 
156
        os_file_t       file;
 
157
        struct PSI_file_locker* locker = NULL;
 
158
        PSI_file_locker_state   state;
 
159
 
 
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)
 
163
                                        ? PSI_FILE_CREATE
 
164
                                        : PSI_FILE_OPEN),
 
165
                                     name, src_file, src_line);
 
166
 
 
167
        file = os_file_create_func(name, create_mode, purpose, type, success);
 
168
 
 
169
        register_pfs_file_open_end(locker, file);
 
170
 
 
171
        return(file);
 
172
}
 
173
 
 
174
/***********************************************************************//**
 
175
NOTE! Please use the corresponding macro os_file_close(), not directly
 
176
this function!
 
177
A performance schema instrumented wrapper function for os_file_close().
 
178
@return TRUE if success */
 
179
UNIV_INLINE
 
180
ibool
 
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 */
 
186
{
 
187
        ibool   result;
 
188
        struct PSI_file_locker* locker = NULL;
 
189
        PSI_file_locker_state   state;
 
190
 
 
191
        /* register the file close */
 
192
        register_pfs_file_io_begin(&state, locker, file, 0, PSI_FILE_CLOSE,
 
193
                                   src_file, src_line);
 
194
 
 
195
        result = os_file_close_func(file);
 
196
 
 
197
        register_pfs_file_io_end(locker, 0);
 
198
 
 
199
        return(result);
 
200
}
 
201
 
 
202
/*******************************************************************//**
 
203
NOTE! Please use the corresponding macro os_aio(), not directly this
 
204
function!
 
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 */
 
208
UNIV_INLINE
 
209
ibool
 
210
pfs_os_aio_func(
 
211
/*============*/
 
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
 
218
                                to write */
 
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
 
222
                                offset */
 
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
 
227
                                OS_AIO_SYNC */
 
228
        void*           message2,/*!< in: message for the aio handler
 
229
                                (can be used to identify a completed
 
230
                                aio operation); ignored if mode is
 
231
                                OS_AIO_SYNC */
 
232
        const char*     src_file,/*!< in: file name where func invoked */
 
233
        ulint           src_line)/*!< in: line where the func invoked */
 
234
{
 
235
        ibool   result;
 
236
        struct PSI_file_locker* locker = NULL;
 
237
        PSI_file_locker_state   state;
 
238
 
 
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)
 
242
                                        ? PSI_FILE_WRITE
 
243
                                        : PSI_FILE_READ,
 
244
                                   src_file, src_line);
 
245
 
 
246
        result = os_aio_func(type, mode, name, file, buf, offset, offset_high,
 
247
                             n, message1, message2);
 
248
 
 
249
        register_pfs_file_io_end(locker, n);
 
250
 
 
251
        return(result);
 
252
}
 
253
 
 
254
/*******************************************************************//**
 
255
NOTE! Please use the corresponding macro os_file_read(), not directly
 
256
this function!
 
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 */
 
260
UNIV_INLINE
 
261
ibool
 
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
 
269
                                offset */
 
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 */
 
273
{
 
274
        ibool   result;
 
275
        struct PSI_file_locker* locker = NULL;
 
276
        PSI_file_locker_state   state;
 
277
 
 
278
        register_pfs_file_io_begin(&state, locker, file, n, PSI_FILE_READ,
 
279
                                   src_file, src_line);
 
280
 
 
281
        result = os_file_read_func(file, buf, offset, offset_high, n);
 
282
 
 
283
        register_pfs_file_io_end(locker, n);
 
284
 
 
285
        return(result);
 
286
}
 
287
 
 
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 */
 
296
UNIV_INLINE
 
297
ibool
 
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
 
305
                                offset */
 
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 */
 
309
{
 
310
        ibool   result;
 
311
        struct PSI_file_locker* locker = NULL;
 
312
        PSI_file_locker_state   state;
 
313
 
 
314
        register_pfs_file_io_begin(&state, locker, file, n, PSI_FILE_READ,
 
315
                                   src_file, src_line);
 
316
 
 
317
        result = os_file_read_no_error_handling_func(file, buf, offset,
 
318
                                                     offset_high, n);
 
319
 
 
320
        register_pfs_file_io_end(locker, n);
 
321
 
 
322
        return(result);
 
323
}
 
324
 
 
325
/*******************************************************************//**
 
326
NOTE! Please use the corresponding macro os_file_write(), not directly
 
327
this function!
 
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 */
 
331
UNIV_INLINE
 
332
ibool
 
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
 
342
                                offset */
 
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 */
 
346
{
 
347
        ibool   result;
 
348
        struct PSI_file_locker* locker = NULL;
 
349
        PSI_file_locker_state   state;
 
350
 
 
351
        register_pfs_file_io_begin(&state, locker, file, n, PSI_FILE_WRITE,
 
352
                                   src_file, src_line);
 
353
 
 
354
        result = os_file_write_func(name, file, buf, offset, offset_high, n);
 
355
 
 
356
        register_pfs_file_io_end(locker, n);
 
357
 
 
358
        return(result);
 
359
}
 
360
 
 
361
/***********************************************************************//**
 
362
NOTE! Please use the corresponding macro os_file_flush(), not directly
 
363
this function!
 
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 */
 
367
UNIV_INLINE
 
368
ibool
 
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 */
 
374
{
 
375
        ibool   result;
 
376
        struct PSI_file_locker* locker = NULL;
 
377
        PSI_file_locker_state   state;
 
378
 
 
379
        register_pfs_file_io_begin(&state, locker, file, 0, PSI_FILE_SYNC,
 
380
                                   src_file, src_line);
 
381
        result = os_file_flush_func(file);
 
382
 
 
383
        register_pfs_file_io_end(locker, 0);
 
384
 
 
385
        return(result);
 
386
}
 
387
 
 
388
/***********************************************************************//**
 
389
NOTE! Please use the corresponding macro os_file_rename(), not directly
 
390
this function!
 
391
This is the performance schema instrumented wrapper function for
 
392
os_file_rename()
 
393
@return TRUE if success */
 
394
UNIV_INLINE
 
395
ibool
 
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
 
400
                                string */
 
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 */
 
404
{
 
405
        ibool   result;
 
406
        struct PSI_file_locker* locker = NULL;
 
407
        PSI_file_locker_state   state;
 
408
 
 
409
        register_pfs_file_open_begin(&state, locker, key, PSI_FILE_RENAME, newpath,
 
410
                                     src_file, src_line);
 
411
 
 
412
        result = os_file_rename_func(oldpath, newpath);
 
413
 
 
414
        register_pfs_file_open_end(locker, 0);
 
415
 
 
416
        return(result);
 
417
}
 
418
#endif /* UNIV_PFS_IO */