#include "univ.i"#include <dirent.h>#include <sys/stat.h>#include <time.h>Include dependency graph for os0file.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
| #define OS_AIO_IBUF 22 |
| #define OS_AIO_LOG 23 |
| #define OS_AIO_NORMAL 21 |
| #define OS_AIO_SIMULATED_WAKE_LATER 512 |
Definition at line 124 of file os0file.h.
Referenced by buf_flush_write_block_low(), buf_read_page_low(), buf_read_recv_pages(), fil_io(), and os_aio().
| #define OS_AIO_SYNC 24 |
Definition at line 114 of file os0file.h.
Referenced by fil_extend_space_to_desired_size(), fil_io(), and os_aio().
| #define OS_DATA_FILE 100 |
Definition at line 87 of file os0file.h.
Referenced by fil_create_new_single_table_tablespace(), fil_node_open_file(), open_or_create_data_files(), and os_file_create().
| #define OS_FILE_AIO 61 |
Definition at line 83 of file os0file.h.
Referenced by fil_node_open_file(), open_or_create_log_file(), and os_file_create().
| #define OS_FILE_AIO_RESOURCES_RESERVED 75 |
Definition at line 95 of file os0file.h.
Referenced by os_file_get_last_error(), os_file_handle_error(), and os_file_handle_error_no_exit().
| #define OS_FILE_ALREADY_EXISTS 73 |
Definition at line 93 of file os0file.h.
Referenced by fil_create_new_single_table_tablespace(), open_or_create_data_files(), open_or_create_log_file(), os_file_get_last_error(), os_file_handle_error(), and os_file_handle_error_no_exit().
| #define OS_FILE_CREATE 52 |
Definition at line 71 of file os0file.h.
Referenced by fil_create_new_single_table_tablespace(), open_or_create_data_files(), open_or_create_log_file(), os_file_create(), os_file_create_simple(), and os_file_create_simple_no_error_handling().
| #define OS_FILE_CREATE_PATH 55 |
| #define OS_FILE_DISK_FULL 72 |
Definition at line 92 of file os0file.h.
Referenced by fil_create_new_single_table_tablespace(), os_file_get_last_error(), os_file_handle_error(), and os_file_handle_error_no_exit().
| #define OS_FILE_LOG 256 |
Definition at line 103 of file os0file.h.
Referenced by fil_io(), log_group_checkpoint(), log_group_file_header_flush(), log_group_read_checkpoint_info(), log_group_read_log_seg(), log_group_write_buf(), and recv_recovery_from_checkpoint_start().
| #define OS_FILE_LOG_BLOCK_SIZE 512 |
Definition at line 67 of file os0file.h.
Referenced by log_check_log_recs(), log_close(), log_group_checkpoint(), log_group_file_header_flush(), log_group_init(), log_group_read_checkpoint_info(), log_group_write_buf(), log_init(), log_sys_check_flush_completion(), log_write_low(), log_write_up_to(), os_aio(), recv_calc_lsn_on_data_add(), recv_copy_group(), recv_recovery_from_checkpoint_start(), recv_reset_logs(), recv_scan_log_recs(), recv_scan_log_seg_for_backup(), recv_synchronize_groups(), recv_sys_add_to_parsing_buf(), recv_sys_init(), and recv_truncate_group().
| #define OS_FILE_MAX_PATH 4000 |
Definition at line 153 of file os0file.h.
Referenced by os_file_opendir(), and os_file_readdir_next_file().
| #define OS_FILE_NORMAL 62 |
Definition at line 84 of file os0file.h.
Referenced by fil_create_new_single_table_tablespace(), open_or_create_data_files(), open_or_create_log_file(), and os_file_create().
| #define OS_FILE_NOT_FOUND 71 |
| #define OS_FILE_OPEN 51 |
Definition at line 70 of file os0file.h.
Referenced by fil_load_single_table_tablespace(), fil_node_open_file(), fil_open_single_table_tablespace(), fil_reset_too_high_lsns(), open_or_create_data_files(), open_or_create_log_file(), os_file_create(), os_file_create_simple(), and os_file_create_simple_no_error_handling().
| #define OS_FILE_OPEN_RAW 54 |
Definition at line 73 of file os0file.h.
Referenced by fil_node_open_file(), open_or_create_data_files(), and os_file_create().
| #define OS_FILE_OPEN_RETRY 56 |
Definition at line 75 of file os0file.h.
Referenced by open_or_create_data_files(), and os_file_create().
| #define OS_FILE_OVERWRITE 53 |
| #define OS_FILE_PATH_ERROR 74 |
Definition at line 94 of file os0file.h.
Referenced by os_file_get_last_error(), os_file_handle_error(), and os_file_handle_error_no_exit().
| #define OS_FILE_READ 10 |
Definition at line 100 of file os0file.h.
Referenced by buf_read_page_low(), fil_io(), fil_read(), fil_space_get_size(), log_group_read_checkpoint_info(), log_group_read_log_seg(), os_aio(), recv_apply_log_recs_for_backup(), recv_recovery_from_checkpoint_start(), and trx_sys_doublewrite_init_or_restore_pages().
| #define OS_FILE_READ_ALLOW_DELETE 555 |
| #define OS_FILE_READ_ONLY 333 |
Definition at line 78 of file os0file.h.
Referenced by fil_load_single_table_tablespace(), fil_node_open_file(), fil_open_single_table_tablespace(), os_file_create_simple(), and os_file_create_simple_no_error_handling().
| #define OS_FILE_READ_WRITE 444 |
Definition at line 79 of file os0file.h.
Referenced by fil_reset_too_high_lsns(), os_file_create_simple(), and os_file_create_simple_no_error_handling().
| #define OS_FILE_WRITE 11 |
Definition at line 101 of file os0file.h.
Referenced by buf_flush_write_block_low(), fil_extend_space_to_desired_size(), fil_io(), fil_node_complete_io(), fil_write(), log_group_checkpoint(), log_group_file_header_flush(), log_group_write_buf(), os_aio(), recv_apply_log_recs_for_backup(), recv_recovery_from_checkpoint_start(), and trx_sys_doublewrite_init_or_restore_pages().
| #define OS_LOG_FILE 101 |
Definition at line 88 of file os0file.h.
Referenced by fil_node_open_file(), open_or_create_log_file(), and os_file_create().
| #define OS_WIN2000 4 |
| #define OS_WIN31 1 |
Definition at line 130 of file os0file.h.
Referenced by innobase_start_or_create_for_mysql(), and os_get_os_version().
| #define OS_WIN95 2 |
Definition at line 131 of file os0file.h.
Referenced by innobase_start_or_create_for_mysql(), and os_get_os_version().
| #define OS_WINNT 3 |
Definition at line 132 of file os0file.h.
Referenced by innobase_start_or_create_for_mysql(), and os_get_os_version().
| typedef struct fil_node_struct fil_node_t |
| typedef DIR* os_file_dir_t |
| typedef struct os_file_stat_struct os_file_stat_t |
| typedef enum os_file_type_enum os_file_type_t |
| enum os_file_type_enum |
Definition at line 141 of file os0file.h.
00141 { 00142 OS_FILE_TYPE_UNKNOWN = 0, 00143 OS_FILE_TYPE_FILE, /* regular file */ 00144 OS_FILE_TYPE_DIR, /* directory */ 00145 OS_FILE_TYPE_LINK /* symbolic link */ 00146 };
| ibool os_aio | ( | ulint | type, | |
| ulint | mode, | |||
| const char * | name, | |||
| os_file_t | file, | |||
| void * | buf, | |||
| ulint | offset, | |||
| ulint | offset_high, | |||
| ulint | n, | |||
| fil_node_t * | message1, | |||
| void * | message2 | |||
| ) |
Definition at line 3305 of file os0file.c.
References err, FALSE, NULL, os_aio_array_free_slot(), os_aio_array_reserve_slot(), os_aio_get_segment_no_from_slot(), OS_AIO_IBUF, os_aio_ibuf_array, OS_AIO_LOG, os_aio_log_array, OS_AIO_NORMAL, os_aio_read_array, os_aio_simulated_wake_handler_thread(), OS_AIO_SIMULATED_WAKE_LATER, OS_AIO_SYNC, os_aio_sync_array, os_aio_use_native_aio, os_aio_validate(), os_aio_write_array, os_bytes_read_since_printout, os_file_handle_error(), OS_FILE_LOG_BLOCK_SIZE, OS_FILE_READ, os_file_read(), OS_FILE_WRITE, os_file_write(), os_n_file_reads, os_n_file_writes, os_aio_slot_struct::pos, TRUE, ut_a, ut_ad, and ut_error.
Referenced by fil_extend_space_to_desired_size().
03307 : TRUE if request was queued 03308 successfully, FALSE if fail */ 03309 ulint type, /* in: OS_FILE_READ or OS_FILE_WRITE */ 03310 ulint mode, /* in: OS_AIO_NORMAL, ..., possibly ORed 03311 to OS_AIO_SIMULATED_WAKE_LATER: the 03312 last flag advises this function not to wake 03313 i/o-handler threads, but the caller will 03314 do the waking explicitly later, in this 03315 way the caller can post several requests in 03316 a batch; NOTE that the batch must not be 03317 so big that it exhausts the slots in aio 03318 arrays! NOTE that a simulated batch 03319 may introduce hidden chances of deadlocks, 03320 because i/os are not actually handled until 03321 all have been posted: use with great 03322 caution! */ 03323 const char* name, /* in: name of the file or path as a 03324 null-terminated string */ 03325 os_file_t file, /* in: handle to a file */ 03326 void* buf, /* in: buffer where to read or from which 03327 to write */ 03328 ulint offset, /* in: least significant 32 bits of file 03329 offset where to read or write */ 03330 ulint offset_high, /* in: most significant 32 bits of 03331 offset */ 03332 ulint n, /* in: number of bytes to read or write */ 03333 fil_node_t* message1,/* in: messages for the aio handler (these 03334 can be used to identify a completed aio 03335 operation); if mode is OS_AIO_SYNC, these 03336 are ignored */ 03337 void* message2) 03338 { 03339 os_aio_array_t* array; 03340 os_aio_slot_t* slot; 03341 #ifdef WIN_ASYNC_IO 03342 ibool retval; 03343 BOOL ret = TRUE; 03344 DWORD len = (DWORD) n; 03345 struct fil_node_struct * dummy_mess1; 03346 void* dummy_mess2; 03347 ulint dummy_type; 03348 #endif 03349 ulint err = 0; 03350 ibool retry; 03351 ulint wake_later; 03352 03353 ut_ad(file); 03354 ut_ad(buf); 03355 ut_ad(n > 0); 03356 ut_ad(n % OS_FILE_LOG_BLOCK_SIZE == 0); 03357 ut_ad(offset % OS_FILE_LOG_BLOCK_SIZE == 0); 03358 ut_ad(os_aio_validate()); 03359 03360 wake_later = mode & OS_AIO_SIMULATED_WAKE_LATER; 03361 mode = mode & (~OS_AIO_SIMULATED_WAKE_LATER); 03362 03363 if (mode == OS_AIO_SYNC 03364 #ifdef WIN_ASYNC_IO 03365 && !os_aio_use_native_aio 03366 #endif 03367 ) { 03368 /* This is actually an ordinary synchronous read or write: 03369 no need to use an i/o-handler thread. NOTE that if we use 03370 Windows async i/o, Windows does not allow us to use 03371 ordinary synchronous os_file_read etc. on the same file, 03372 therefore we have built a special mechanism for synchronous 03373 wait in the Windows case. */ 03374 03375 if (type == OS_FILE_READ) { 03376 return(os_file_read(file, buf, offset, 03377 offset_high, n)); 03378 } 03379 03380 ut_a(type == OS_FILE_WRITE); 03381 03382 return(os_file_write(name, file, buf, offset, offset_high, n)); 03383 } 03384 03385 try_again: 03386 if (mode == OS_AIO_NORMAL) { 03387 if (type == OS_FILE_READ) { 03388 array = os_aio_read_array; 03389 } else { 03390 array = os_aio_write_array; 03391 } 03392 } else if (mode == OS_AIO_IBUF) { 03393 ut_ad(type == OS_FILE_READ); 03394 /* Reduce probability of deadlock bugs in connection with ibuf: 03395 do not let the ibuf i/o handler sleep */ 03396 03397 wake_later = FALSE; 03398 03399 array = os_aio_ibuf_array; 03400 } else if (mode == OS_AIO_LOG) { 03401 03402 array = os_aio_log_array; 03403 } else if (mode == OS_AIO_SYNC) { 03404 array = os_aio_sync_array; 03405 } else { 03406 array = NULL; /* Eliminate compiler warning */ 03407 ut_error; 03408 } 03409 03410 slot = os_aio_array_reserve_slot(type, array, message1, message2, file, 03411 name, buf, offset, offset_high, n); 03412 if (type == OS_FILE_READ) { 03413 if (os_aio_use_native_aio) { 03414 #ifdef WIN_ASYNC_IO 03415 os_n_file_reads++; 03416 os_bytes_read_since_printout += len; 03417 03418 ret = ReadFile(file, buf, (DWORD)n, &len, 03419 &(slot->control)); 03420 #elif defined(POSIX_ASYNC_IO) 03421 slot->control.aio_lio_opcode = LIO_READ; 03422 err = (ulint) aio_read(&(slot->control)); 03423 fprintf(stderr, "Starting POSIX aio read %lu\n", err); 03424 #endif 03425 } else { 03426 if (!wake_later) { 03427 os_aio_simulated_wake_handler_thread( 03428 os_aio_get_segment_no_from_slot(array, slot)); 03429 } 03430 } 03431 } else if (type == OS_FILE_WRITE) { 03432 if (os_aio_use_native_aio) { 03433 #ifdef WIN_ASYNC_IO 03434 os_n_file_writes++; 03435 ret = WriteFile(file, buf, (DWORD)n, &len, 03436 &(slot->control)); 03437 #elif defined(POSIX_ASYNC_IO) 03438 slot->control.aio_lio_opcode = LIO_WRITE; 03439 err = (ulint) aio_write(&(slot->control)); 03440 fprintf(stderr, "Starting POSIX aio write %lu\n", err); 03441 #endif 03442 } else { 03443 if (!wake_later) { 03444 os_aio_simulated_wake_handler_thread( 03445 os_aio_get_segment_no_from_slot(array, slot)); 03446 } 03447 } 03448 } else { 03449 ut_error; 03450 } 03451 03452 #ifdef WIN_ASYNC_IO 03453 if (os_aio_use_native_aio) { 03454 if ((ret && len == n) 03455 || (!ret && GetLastError() == ERROR_IO_PENDING)) { 03456 /* aio was queued successfully! */ 03457 03458 if (mode == OS_AIO_SYNC) { 03459 /* We want a synchronous i/o operation on a 03460 file where we also use async i/o: in Windows 03461 we must use the same wait mechanism as for 03462 async i/o */ 03463 03464 retval = os_aio_windows_handle(ULINT_UNDEFINED, 03465 slot->pos, 03466 &dummy_mess1, &dummy_mess2, 03467 &dummy_type); 03468 03469 return(retval); 03470 } 03471 03472 return(TRUE); 03473 } 03474 03475 err = 1; /* Fall through the next if */ 03476 } 03477 #endif 03478 if (err == 0) { 03479 /* aio was queued successfully! */ 03480 03481 return(TRUE); 03482 } 03483 03484 os_aio_array_free_slot(array, slot); 03485 03486 retry = os_file_handle_error(name, 03487 type == OS_FILE_READ ? "aio read" : "aio write"); 03488 if (retry) { 03489 03490 goto try_again; 03491 } 03492 03493 return(FALSE); 03494 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2789 of file os0file.c.
References NULL, os_aio_array_create(), os_aio_ibuf_array, os_aio_log_array, os_aio_n_segments, os_aio_read_array, os_aio_segment_wait_events, os_aio_sync_array, os_aio_validate(), os_aio_write_array, os_event_create(), os_io_init_simple(), os_last_printout, sigemptyset, srv_io_thread_function, SRV_MAX_N_IO_THREADS, srv_set_io_thread_op_info(), ut_a, ut_ad, and ut_malloc().
Referenced by innobase_start_or_create_for_mysql().
02791 : maximum number of pending aio operations 02792 allowed; n must be divisible by n_segments */ 02793 ulint n_segments, /* in: combined number of segments in the four 02794 first aio arrays; must be >= 4 */ 02795 ulint n_slots_sync) /* in: number of slots in the sync aio array */ 02796 { 02797 ulint n_read_segs; 02798 ulint n_write_segs; 02799 ulint n_per_seg; 02800 ulint i; 02801 #ifdef POSIX_ASYNC_IO 02802 sigset_t sigset; 02803 #endif 02804 ut_ad(n % n_segments == 0); 02805 ut_ad(n_segments >= 4); 02806 02807 os_io_init_simple(); 02808 02809 for (i = 0; i < n_segments; i++) { 02810 srv_set_io_thread_op_info(i, "not started yet"); 02811 } 02812 02813 n_per_seg = n / n_segments; 02814 n_write_segs = (n_segments - 2) / 2; 02815 n_read_segs = n_segments - 2 - n_write_segs; 02816 02817 /* fprintf(stderr, "Array n per seg %lu\n", n_per_seg); */ 02818 02819 os_aio_ibuf_array = os_aio_array_create(n_per_seg, 1); 02820 02821 srv_io_thread_function[0] = "insert buffer thread"; 02822 02823 os_aio_log_array = os_aio_array_create(n_per_seg, 1); 02824 02825 srv_io_thread_function[1] = "log thread"; 02826 02827 os_aio_read_array = os_aio_array_create(n_read_segs * n_per_seg, 02828 n_read_segs); 02829 for (i = 2; i < 2 + n_read_segs; i++) { 02830 ut_a(i < SRV_MAX_N_IO_THREADS); 02831 srv_io_thread_function[i] = "read thread"; 02832 } 02833 02834 os_aio_write_array = os_aio_array_create(n_write_segs * n_per_seg, 02835 n_write_segs); 02836 for (i = 2 + n_read_segs; i < n_segments; i++) { 02837 ut_a(i < SRV_MAX_N_IO_THREADS); 02838 srv_io_thread_function[i] = "write thread"; 02839 } 02840 02841 os_aio_sync_array = os_aio_array_create(n_slots_sync, 1); 02842 02843 os_aio_n_segments = n_segments; 02844 02845 os_aio_validate(); 02846 02847 os_aio_segment_wait_events = ut_malloc(n_segments * sizeof(void*)); 02848 02849 for (i = 0; i < n_segments; i++) { 02850 os_aio_segment_wait_events[i] = os_event_create(NULL); 02851 } 02852 02853 os_last_printout = time(NULL); 02854 02855 #ifdef POSIX_ASYNC_IO 02856 /* Block aio signals from the current thread and its children: 02857 for this to work, the current thread must be the first created 02858 in the database, so that all its children will inherit its 02859 signal mask */ 02860 02861 /* TODO: to work MySQL needs the SIGALARM signal; the following 02862 will not work yet! */ 02863 sigemptyset(&sigset); 02864 sigaddset(&sigset, SIGRTMIN + 1 + 0); 02865 sigaddset(&sigset, SIGRTMIN + 1 + 1); 02866 sigaddset(&sigset, SIGRTMIN + 1 + 2); 02867 sigaddset(&sigset, SIGRTMIN + 1 + 3); 02868 02869 pthread_sigmask(SIG_BLOCK, &sigset, NULL); */ 02870 #endif 02871 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void os_aio_print | ( | FILE * | file | ) |
Definition at line 4102 of file os0file.c.
References current_time(), os_aio_slot_struct::len, os_aio_array_struct::mutex, os_aio_array_struct::n_segments, os_aio_array_struct::n_slots, os_aio_array_get_nth_slot(), os_aio_read_array, os_aio_segment_wait_events, os_mutex_enter(), os_aio_slot_struct::reserved, srv_io_thread_function, srv_io_thread_op_info, srv_n_file_io_threads, and ut_a.
Referenced by srv_printf_innodb_monitor().
04104 : file where to print */ 04105 { 04106 os_aio_array_t* array; 04107 os_aio_slot_t* slot; 04108 ulint n_reserved; 04109 time_t current_time; 04110 double time_elapsed; 04111 double avg_bytes_read; 04112 ulint i; 04113 04114 for (i = 0; i < srv_n_file_io_threads; i++) { 04115 fprintf(file, "I/O thread %lu state: %s (%s)", (ulong) i, 04116 srv_io_thread_op_info[i], 04117 srv_io_thread_function[i]); 04118 04119 #ifndef __WIN__ 04120 if (os_aio_segment_wait_events[i]->is_set) { 04121 fprintf(file, " ev set"); 04122 } 04123 #endif 04124 04125 fprintf(file, "\n"); 04126 } 04127 04128 fputs("Pending normal aio reads:", file); 04129 04130 array = os_aio_read_array; 04131 loop: 04132 ut_a(array); 04133 04134 os_mutex_enter(array->mutex); 04135 04136 ut_a(array->n_slots > 0); 04137 ut_a(array->n_segments > 0); 04138 04139 n_reserved = 0; 04140 04141 for (i = 0; i < array->n_slots; i++) { 04142 slot = os_aio_array_get_nth_slot(array, i); 04143 04144 if (slot->reserved) { 04145 n_reserved++; 04146 /* fprintf(stderr, "Reserved slot, messages %p %p\n", 04147 slot->message1, slot->message2); */ 04148 ut_a(slot->len > 0); 04149 } 04150 } 04151 04152 ut_a(array->n_reserved == n_reserved); 04153 04154 fprintf(file, " %lu", (ulong) n_reserved); 04155 04156 os_mutex_exit(array->mutex); 04157 04158 if (array == os_aio_read_array) { 04159 fputs(", aio writes:", file); 04160 04161 array = os_aio_write_array; 04162 04163 goto loop; 04164 } 04165 04166 if (array == os_aio_write_array) { 04167 fputs(",\n ibuf aio reads:", file); 04168 array = os_aio_ibuf_array; 04169 04170 goto loop; 04171 } 04172 04173 if (array == os_aio_ibuf_array) { 04174 fputs(", log i/o's:", file); 04175 array = os_aio_log_array; 04176 04177 goto loop; 04178 } 04179 04180 if (array == os_aio_log_array) { 04181 fputs(", sync i/o's:", file); 04182 array = os_aio_sync_array; 04183 04184 goto loop; 04185 } 04186 04187 putc('\n', file); 04188 current_time = time(NULL); 04189 time_elapsed = 0.001 + difftime(current_time, os_last_printout); 04190 04191 fprintf(file, 04192 "Pending flushes (fsync) log: %lu; buffer pool: %lu\n" 04193 "%lu OS file reads, %lu OS file writes, %lu OS fsyncs\n", 04194 (ulong) fil_n_pending_log_flushes, 04195 (ulong) fil_n_pending_tablespace_flushes, 04196 (ulong) os_n_file_reads, (ulong) os_n_file_writes, 04197 (ulong) os_n_fsyncs); 04198 04199 if (os_file_n_pending_preads != 0 || os_file_n_pending_pwrites != 0) { 04200 fprintf(file, 04201 "%lu pending preads, %lu pending pwrites\n", 04202 (ulong) os_file_n_pending_preads, 04203 (ulong) os_file_n_pending_pwrites); 04204 } 04205 04206 if (os_n_file_reads == os_n_file_reads_old) { 04207 avg_bytes_read = 0.0; 04208 } else { 04209 avg_bytes_read = (double) os_bytes_read_since_printout / 04210 (os_n_file_reads - os_n_file_reads_old); 04211 } 04212 04213 fprintf(file, 04214 "%.2f reads/s, %lu avg bytes/read, %.2f writes/s, %.2f fsyncs/s\n", 04215 (os_n_file_reads - os_n_file_reads_old) 04216 / time_elapsed, 04217 (ulong)avg_bytes_read, 04218 (os_n_file_writes - os_n_file_writes_old) 04219 / time_elapsed, 04220 (os_n_fsyncs - os_n_fsyncs_old) 04221 / time_elapsed); 04222 04223 os_n_file_reads_old = os_n_file_reads; 04224 os_n_file_writes_old = os_n_file_writes; 04225 os_n_fsyncs_old = os_n_fsyncs; 04226 os_bytes_read_since_printout = 0; 04227 04228 os_last_printout = current_time; 04229 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void os_aio_refresh_stats | ( | void | ) |
Definition at line 4235 of file os0file.c.
References os_bytes_read_since_printout, os_last_printout, os_n_file_reads_old, os_n_file_writes_old, os_n_fsyncs, and os_n_fsyncs_old.
Referenced by srv_refresh_innodb_monitor_stats().
04237 { 04238 os_n_file_reads_old = os_n_file_reads; 04239 os_n_file_writes_old = os_n_file_writes; 04240 os_n_fsyncs_old = os_n_fsyncs; 04241 os_bytes_read_since_printout = 0; 04242 04243 os_last_printout = time(NULL); 04244 }
Here is the caller graph for this function:

| ibool os_aio_simulated_handle | ( | ulint | segment, | |
| fil_node_t ** | message1, | |||
| void ** | message2, | |||
| ulint * | type | |||
| ) |
Definition at line 3718 of file os0file.c.
References os_aio_slot_struct::io_already_done, os_aio_array_struct::mutex, os_aio_array_struct::n_segments, os_aio_array_struct::n_slots, os_aio_array_get_nth_slot(), os_aio_get_array_and_local_segment(), OS_AIO_MERGE_N_CONSECUTIVE, os_aio_print_debug, os_aio_read_array, os_aio_recommend_sleep_for_read_threads, os_aio_validate(), os_mutex_enter(), os_aio_slot_struct::reserved, srv_set_io_thread_op_info(), TRUE, and ut_ad.
Referenced by fil_aio_wait().
03720 : TRUE if the aio operation succeeded */ 03721 ulint global_segment, /* in: the number of the segment in the aio 03722 arrays to wait for; segment 0 is the ibuf 03723 i/o thread, segment 1 the log i/o thread, 03724 then follow the non-ibuf read threads, and as 03725 the last are the non-ibuf write threads */ 03726 fil_node_t**message1, /* out: the messages passed with the aio 03727 request; note that also in the case where 03728 the aio operation failed, these output 03729 parameters are valid and can be used to 03730 restart the operation, for example */ 03731 void** message2, 03732 ulint* type) /* out: OS_FILE_WRITE or ..._READ */ 03733 { 03734 os_aio_array_t* array; 03735 ulint segment; 03736 os_aio_slot_t* slot; 03737 os_aio_slot_t* slot2; 03738 os_aio_slot_t* consecutive_ios[OS_AIO_MERGE_N_CONSECUTIVE]; 03739 ulint n_consecutive; 03740 ulint total_len; 03741 ulint offs; 03742 ulint lowest_offset; 03743 ulint biggest_age; 03744 ulint age; 03745 byte* combined_buf; 03746 byte* combined_buf2; 03747 ibool ret; 03748 ulint n; 03749 ulint i; 03750 03751 segment = os_aio_get_array_and_local_segment(&array, global_segment); 03752 03753 restart: 03754 /* NOTE! We only access constant fields in os_aio_array. Therefore 03755 we do not have to acquire the protecting mutex yet */ 03756 03757 srv_set_io_thread_op_info(global_segment, 03758 "looking for i/o requests (a)"); 03759 ut_ad(os_aio_validate()); 03760 ut_ad(segment < array->n_segments); 03761 03762 n = array->n_slots / array->n_segments; 03763 03764 /* Look through n slots after the segment * n'th slot */ 03765 03766 if (array == os_aio_read_array 03767 && os_aio_recommend_sleep_for_read_threads) { 03768 03769 /* Give other threads chance to add several i/os to the array 03770 at once. */ 03771 03772 goto recommended_sleep; 03773 } 03774 03775 os_mutex_enter(array->mutex); 03776 03777 srv_set_io_thread_op_info(global_segment, 03778 "looking for i/o requests (b)"); 03779 03780 /* Check if there is a slot for which the i/o has already been 03781 done */ 03782 03783 for (i = 0; i < n; i++) { 03784 slot = os_aio_array_get_nth_slot(array, i + segment * n); 03785 03786 if (slot->reserved && slot->io_already_done) { 03787 03788 if (os_aio_print_debug) { 03789 fprintf(stderr, 03790 "InnoDB: i/o for slot %lu already done, returning\n", (ulong) i); 03791 } 03792 03793 ret = TRUE; 03794 03795 goto slot_io_done; 03796 } 03797 } 03798 03799 n_consecutive = 0; 03800 03801 /* If there are at least 2 seconds old requests, then pick the oldest 03802 one to prevent starvation. If several requests have the same age, 03803 then pick the one at the lowest offset. */ 03804 03805 biggest_age = 0; 03806 lowest_offset = ULINT_MAX; 03807 03808 for (i = 0; i < n; i++) { 03809 slot = os_aio_array_get_nth_slot(array, i + segment * n); 03810 03811 if (slot->reserved) { 03812 age = (ulint)difftime(time(NULL), 03813 slot->reservation_time); 03814 03815 if ((age >= 2 && age > biggest_age) 03816 || (age >= 2 && age == biggest_age 03817 && slot->offset < lowest_offset)) { 03818 03819 /* Found an i/o request */ 03820 consecutive_ios[0] = slot; 03821 03822 n_consecutive = 1; 03823 03824 biggest_age = age; 03825 lowest_offset = slot->offset; 03826 } 03827 } 03828 } 03829 03830 if (n_consecutive == 0) { 03831 /* There were no old requests. Look for an i/o request at the 03832 lowest offset in the array (we ignore the high 32 bits of the 03833 offset in these heuristics) */ 03834 03835 lowest_offset = ULINT_MAX; 03836 03837 for (i = 0; i < n; i++) { 03838 slot = os_aio_array_get_nth_slot(array, 03839 i + segment * n); 03840 03841 if (slot->reserved && slot->offset < lowest_offset) { 03842 03843 /* Found an i/o request */ 03844 consecutive_ios[0] = slot; 03845 03846 n_consecutive = 1; 03847 03848 lowest_offset = slot->offset; 03849 } 03850 } 03851 } 03852 03853 if (n_consecutive == 0) { 03854 03855 /* No i/o requested at the moment */ 03856 03857 goto wait_for_io; 03858 } 03859 03860 slot = consecutive_ios[0]; 03861 03862 /* Check if there are several consecutive blocks to read or write */ 03863 03864 consecutive_loop: 03865 for (i = 0; i < n; i++) { 03866 slot2 = os_aio_array_get_nth_slot(array, i + segment * n); 03867 03868 if (slot2->reserved && slot2 != slot 03869 && slot2->offset == slot->offset + slot->len 03870 /* check that sum does not wrap over */ 03871 && slot->offset + slot->len > slot->offset 03872 && slot2->offset_high == slot->offset_high 03873 && slot2->type == slot->type 03874 && slot2->file == slot->file) { 03875 03876 /* Found a consecutive i/o request */ 03877 03878 consecutive_ios[n_consecutive] = slot2; 03879 n_consecutive++; 03880 03881 slot = slot2; 03882 03883 if (n_consecutive < OS_AIO_MERGE_N_CONSECUTIVE) { 03884 03885 goto consecutive_loop; 03886 } else { 03887 break; 03888 } 03889 } 03890 } 03891 03892 srv_set_io_thread_op_info(global_segment, "consecutive i/o requests"); 03893 03894 /* We have now collected n_consecutive i/o requests in the array; 03895 allocate a single buffer which can hold all data, and perform the 03896 i/o */ 03897 03898 total_len = 0; 03899 slot = consecutive_ios[0]; 03900 03901 for (i = 0; i < n_consecutive; i++) { 03902 total_len += consecutive_ios[i]->len; 03903 } 03904 03905 if (n_consecutive == 1) { 03906 /* We can use the buffer of the i/o request */ 03907 combined_buf = slot->buf; 03908 combined_buf2 = NULL; 03909 } else { 03910 combined_buf2 = ut_malloc(total_len + UNIV_PAGE_SIZE); 03911 03912 ut_a(combined_buf2); 03913 03914 combined_buf = ut_align(combined_buf2, UNIV_PAGE_SIZE); 03915 } 03916 03917 /* We release the array mutex for the time of the i/o: NOTE that 03918 this assumes that there is just one i/o-handler thread serving 03919 a single segment of slots! */ 03920 03921 os_mutex_exit(array->mutex); 03922 03923 if (slot->type == OS_FILE_WRITE && n_consecutive > 1) { 03924 /* Copy the buffers to the combined buffer */ 03925 offs = 0; 03926 03927 for (i = 0; i < n_consecutive; i++) { 03928 03929 ut_memcpy(combined_buf + offs, consecutive_ios[i]->buf, 03930 consecutive_ios[i]->len); 03931 offs += consecutive_ios[i]->len; 03932 } 03933 } 03934 03935 srv_set_io_thread_op_info(global_segment, "doing file i/o"); 03936 03937 if (os_aio_print_debug) { 03938 fprintf(stderr, 03939 "InnoDB: doing i/o of type %lu at offset %lu %lu, length %lu\n", 03940 (ulong) slot->type, (ulong) slot->offset_high, 03941 (ulong) slot->offset, (ulong) total_len); 03942 } 03943 03944 /* Do the i/o with ordinary, synchronous i/o functions: */ 03945 if (slot->type == OS_FILE_WRITE) { 03946 if (array == os_aio_write_array) { 03947 if ((total_len % UNIV_PAGE_SIZE != 0) 03948 || (slot->offset % UNIV_PAGE_SIZE != 0)) { 03949 fprintf(stderr, 03950 "InnoDB: Error: trying a displaced write to %s %lu %lu, len %lu\n", 03951 slot->name, (ulong) slot->offset_high, 03952 (ulong) slot->offset, 03953 (ulong) total_len); 03954 ut_error; 03955 } 03956 03957 os_file_check_page_trailers(combined_buf, total_len); 03958 } 03959 03960 ret = os_file_write(slot->name, slot->file, combined_buf, 03961 slot->offset, slot->offset_high, total_len); 03962 03963 if (array == os_aio_write_array) { 03964 os_file_check_page_trailers(combined_buf, total_len); 03965 } 03966 } else { 03967 ret = os_file_read(slot->file, combined_buf, 03968 slot->offset, slot->offset_high, total_len); 03969 } 03970 03971 ut_a(ret); 03972 srv_set_io_thread_op_info(global_segment, "file i/o done"); 03973 03974 /* fprintf(stderr, 03975 "aio: %lu consecutive %lu:th segment, first offs %lu blocks\n", 03976 n_consecutive, global_segment, slot->offset / UNIV_PAGE_SIZE); */ 03977 03978 if (slot->type == OS_FILE_READ && n_consecutive > 1) { 03979 /* Copy the combined buffer to individual buffers */ 03980 offs = 0; 03981 03982 for (i = 0; i < n_consecutive; i++) { 03983 03984 ut_memcpy(consecutive_ios[i]->buf, combined_buf + offs, 03985 consecutive_ios[i]->len); 03986 offs += consecutive_ios[i]->len; 03987 } 03988 } 03989 03990 if (combined_buf2) { 03991 ut_free(combined_buf2); 03992 } 03993 03994 os_mutex_enter(array->mutex); 03995 03996 /* Mark the i/os done in slots */ 03997 03998 for (i = 0; i < n_consecutive; i++) { 03999 consecutive_ios[i]->io_already_done = TRUE; 04000 } 04001 04002 /* We return the messages for the first slot now, and if there were 04003 several slots, the messages will be returned with subsequent calls 04004 of this function */ 04005 04006 slot_io_done: 04007 04008 ut_a(slot->reserved); 04009 04010 *message1 = slot->message1; 04011 *message2 = slot->message2; 04012 04013 *type = slot->type; 04014 04015 os_mutex_exit(array->mutex); 04016 04017 os_aio_array_free_slot(array, slot); 04018 04019 return(ret); 04020 04021 wait_for_io: 04022 srv_set_io_thread_op_info(global_segment, "resetting wait event"); 04023 04024 /* We wait here until there again can be i/os in the segment 04025 of this thread */ 04026 04027 os_event_reset(os_aio_segment_wait_events[global_segment]); 04028 04029 os_mutex_exit(array->mutex); 04030 04031 recommended_sleep: 04032 srv_set_io_thread_op_info(global_segment, "waiting for i/o request"); 04033 04034 os_event_wait(os_aio_segment_wait_events[global_segment]); 04035 04036 if (os_aio_print_debug) { 04037 fprintf(stderr, 04038 "InnoDB: i/o handler thread for i/o segment %lu wakes up\n", 04039 (ulong) global_segment); 04040 } 04041 04042 goto restart; 04043 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void os_aio_simulated_put_read_threads_to_sleep | ( | void | ) |
Definition at line 3283 of file os0file.c.
References os_aio_get_array_and_local_segment(), os_aio_n_segments, os_aio_read_array, os_aio_recommend_sleep_for_read_threads, os_aio_segment_wait_events, os_event_reset(), and TRUE.
03285 { 03286 os_aio_array_t* array; 03287 ulint g; 03288 03289 os_aio_recommend_sleep_for_read_threads = TRUE; 03290 03291 for (g = 0; g < os_aio_n_segments; g++) { 03292 os_aio_get_array_and_local_segment(&array, g); 03293 03294 if (array == os_aio_read_array) { 03295 03296 os_event_reset(os_aio_segment_wait_events[g]); 03297 } 03298 } 03299 }
Here is the call graph for this function:

| void os_aio_simulated_wake_handler_threads | ( | void | ) |
Definition at line 3258 of file os0file.c.
References FALSE, os_aio_n_segments, os_aio_recommend_sleep_for_read_threads, os_aio_simulated_wake_handler_thread(), and os_aio_use_native_aio.
Referenced by buf_flush_buffered_writes(), buf_LRU_get_free_block(), buf_read_ibuf_merge_pages(), buf_read_recv_pages(), fil_mutex_enter_and_prepare_for_io(), and os_aio_array_reserve_slot().
03260 { 03261 ulint i; 03262 03263 if (os_aio_use_native_aio) { 03264 /* We do not use simulated aio: do nothing */ 03265 03266 return; 03267 } 03268 03269 os_aio_recommend_sleep_for_read_threads = FALSE; 03270 03271 for (i = 0; i < os_aio_n_segments; i++) { 03272 os_aio_simulated_wake_handler_thread(i); 03273 } 03274 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_aio_validate | ( | void | ) |
Definition at line 4085 of file os0file.c.
References os_aio_array_validate(), os_aio_ibuf_array, os_aio_log_array, os_aio_read_array, os_aio_sync_array, os_aio_write_array, and TRUE.
Referenced by os_aio(), os_aio_init(), and os_aio_simulated_handle().
04087 : TRUE if ok */ 04088 { 04089 os_aio_array_validate(os_aio_read_array); 04090 os_aio_array_validate(os_aio_write_array); 04091 os_aio_array_validate(os_aio_ibuf_array); 04092 os_aio_array_validate(os_aio_log_array); 04093 os_aio_array_validate(os_aio_sync_array); 04094 04095 return(TRUE); 04096 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void os_aio_wait_until_no_pending_writes | ( | void | ) |
Definition at line 2922 of file os0file.c.
References os_aio_array_struct::is_empty, os_aio_write_array, and os_event_wait().
02924 { 02925 os_event_wait(os_aio_write_array->is_empty); 02926 }
Here is the call graph for this function:

| void os_aio_wake_all_threads_at_shutdown | ( | void | ) |
Definition at line 2897 of file os0file.c.
References os_aio_ibuf_array, os_aio_log_array, os_aio_n_segments, os_aio_read_array, os_aio_segment_wait_events, os_aio_write_array, and os_event_set().
Referenced by innobase_shutdown_for_mysql().
02899 { 02900 ulint i; 02901 02902 #ifdef WIN_ASYNC_IO 02903 /* This code wakes up all ai/o threads in Windows native aio */ 02904 os_aio_array_wake_win_aio_at_shutdown(os_aio_read_array); 02905 os_aio_array_wake_win_aio_at_shutdown(os_aio_write_array); 02906 os_aio_array_wake_win_aio_at_shutdown(os_aio_ibuf_array); 02907 os_aio_array_wake_win_aio_at_shutdown(os_aio_log_array); 02908 #endif 02909 /* This loop wakes up all simulated ai/o threads */ 02910 02911 for (i = 0; i < os_aio_n_segments; i++) { 02912 02913 os_event_set(os_aio_segment_wait_events[i]); 02914 } 02915 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_file_close | ( | os_file_t | file | ) |
Definition at line 1499 of file os0file.c.
References FALSE, NULL, os_file_handle_error(), TRUE, and ut_a.
Referenced by fil_create_new_single_table_tablespace(), fil_load_single_table_tablespace(), fil_node_close_file(), fil_node_open_file(), fil_open_single_table_tablespace(), fil_reset_too_high_lsns(), open_or_create_data_files(), and open_or_create_log_file().
01501 : TRUE if success */ 01502 os_file_t file) /* in, own: handle to a file */ 01503 { 01504 #ifdef __WIN__ 01505 BOOL ret; 01506 01507 ut_a(file); 01508 01509 ret = CloseHandle(file); 01510 01511 if (ret) { 01512 return(TRUE); 01513 } 01514 01515 os_file_handle_error(NULL, "close"); 01516 01517 return(FALSE); 01518 #else 01519 int ret; 01520 01521 ret = close(file); 01522 01523 if (ret == -1) { 01524 os_file_handle_error(NULL, "close"); 01525 01526 return(FALSE); 01527 } 01528 01529 return(TRUE); 01530 #endif 01531 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_file_close_no_error_handling | ( | os_file_t | file | ) |
Definition at line 1537 of file os0file.c.
References FALSE, TRUE, and ut_a.
01539 : TRUE if success */ 01540 os_file_t file) /* in, own: handle to a file */ 01541 { 01542 #ifdef __WIN__ 01543 BOOL ret; 01544 01545 ut_a(file); 01546 01547 ret = CloseHandle(file); 01548 01549 if (ret) { 01550 return(TRUE); 01551 } 01552 01553 return(FALSE); 01554 #else 01555 int ret; 01556 01557 ret = close(file); 01558 01559 if (ret == -1) { 01560 01561 return(FALSE); 01562 } 01563 01564 return(TRUE); 01565 #endif 01566 }
| int os_file_closedir | ( | os_file_dir_t | dir | ) |
Definition at line 621 of file os0file.c.
References NULL, and os_file_handle_error_no_exit().
Referenced by fil_load_single_table_tablespaces().
00623 : 0 if success, -1 if failure */ 00624 os_file_dir_t dir) /* in: directory stream */ 00625 { 00626 #ifdef __WIN__ 00627 BOOL ret; 00628 00629 ret = FindClose(dir); 00630 00631 if (!ret) { 00632 os_file_handle_error_no_exit(NULL, "closedir"); 00633 00634 return(-1); 00635 } 00636 00637 return(0); 00638 #else 00639 int ret; 00640 00641 ret = closedir(dir); 00642 00643 if (ret) { 00644 os_file_handle_error_no_exit(NULL, "closedir"); 00645 } 00646 00647 return(ret); 00648 #endif 00649 }
Here is the call graph for this function:

Here is the caller graph for this function:

| os_file_t os_file_create | ( | const char * | name, | |
| ulint | create_mode, | |||
| ulint | purpose, | |||
| ulint | type, | |||
| ibool * | success | |||
| ) |
Definition at line 1102 of file os0file.c.
References create_flag, FALSE, NULL, os_aio_use_native_aio, OS_DATA_FILE, OS_FILE_AIO, OS_FILE_CREATE, os_file_handle_error(), os_file_lock(), OS_FILE_NORMAL, OS_FILE_OPEN, OS_FILE_OPEN_RAW, OS_FILE_OPEN_RETRY, OS_FILE_OVERWRITE, os_innodb_umask, OS_LOG_FILE, os_thread_sleep(), srv_flush_log_at_trx_commit, srv_unix_file_flush_method, SRV_UNIX_O_DIRECT, SRV_UNIX_O_DSYNC, srv_win_file_flush_method, SRV_WIN_IO_UNBUFFERED, TRUE, ut_a, ut_error, and ut_print_timestamp().
Referenced by fil_create_new_single_table_tablespace(), fil_node_open_file(), open_or_create_data_files(), and open_or_create_log_file().
01104 : handle to the file, not defined 01105 if error, error number can be retrieved with 01106 os_file_get_last_error */ 01107 const char* name, /* in: name of the file or path as a 01108 null-terminated string */ 01109 ulint create_mode,/* in: OS_FILE_OPEN if an existing file 01110 is opened (if does not exist, error), or 01111 OS_FILE_CREATE if a new file is created 01112 (if exists, error), 01113 OS_FILE_OVERWRITE if a new file is created 01114 or an old overwritten; 01115 OS_FILE_OPEN_RAW, if a raw device or disk 01116 partition should be opened */ 01117 ulint purpose,/* in: OS_FILE_AIO, if asynchronous, 01118 non-buffered i/o is desired, 01119 OS_FILE_NORMAL, if any normal file; 01120 NOTE that it also depends on type, os_aio_.. 01121 and srv_.. variables whether we really use 01122 async i/o or unbuffered i/o: look in the 01123 function source code for the exact rules */ 01124 ulint type, /* in: OS_DATA_FILE or OS_LOG_FILE */ 01125 ibool* success)/* out: TRUE if succeed, FALSE if error */ 01126 { 01127 #ifdef __WIN__ 01128 os_file_t file; 01129 DWORD share_mode = FILE_SHARE_READ; 01130 DWORD create_flag; 01131 DWORD attributes; 01132 ibool retry; 01133 try_again: 01134 ut_a(name); 01135 01136 if (create_mode == OS_FILE_OPEN_RAW) { 01137 create_flag = OPEN_EXISTING; 01138 share_mode = FILE_SHARE_WRITE; 01139 } else if (create_mode == OS_FILE_OPEN 01140 || create_mode == OS_FILE_OPEN_RETRY) { 01141 create_flag = OPEN_EXISTING; 01142 } else if (create_mode == OS_FILE_CREATE) { 01143 create_flag = CREATE_NEW; 01144 } else if (create_mode == OS_FILE_OVERWRITE) { 01145 create_flag = CREATE_ALWAYS; 01146 } else { 01147 create_flag = 0; 01148 ut_error; 01149 } 01150 01151 if (purpose == OS_FILE_AIO) { 01152 /* If specified, use asynchronous (overlapped) io and no 01153 buffering of writes in the OS */ 01154 attributes = 0; 01155 #ifdef WIN_ASYNC_IO 01156 if (os_aio_use_native_aio) { 01157 attributes = attributes | FILE_FLAG_OVERLAPPED; 01158 } 01159 #endif 01160 #ifdef UNIV_NON_BUFFERED_IO 01161 if (type == OS_LOG_FILE && srv_flush_log_at_trx_commit == 2) { 01162 /* Do not use unbuffered i/o to log files because 01163 value 2 denotes that we do not flush the log at every 01164 commit, but only once per second */ 01165 } else if (srv_win_file_flush_method == 01166 SRV_WIN_IO_UNBUFFERED) { 01167 attributes = attributes | FILE_FLAG_NO_BUFFERING; 01168 } 01169 #endif 01170 } else if (purpose == OS_FILE_NORMAL) { 01171 attributes = 0; 01172 #ifdef UNIV_NON_BUFFERED_IO 01173 if (type == OS_LOG_FILE && srv_flush_log_at_trx_commit == 2) { 01174 /* Do not use unbuffered i/o to log files because 01175 value 2 denotes that we do not flush the log at every 01176 commit, but only once per second */ 01177 } else if (srv_win_file_flush_method == 01178 SRV_WIN_IO_UNBUFFERED) { 01179 attributes = attributes | FILE_FLAG_NO_BUFFERING; 01180 } 01181 #endif 01182 } else { 01183 attributes = 0; 01184 ut_error; 01185 } 01186 01187 file = CreateFile((LPCTSTR) name, 01188 GENERIC_READ | GENERIC_WRITE, /* read and write 01189 access */ 01190 share_mode, /* File can be read also by other 01191 processes; we must give the read 01192 permission because of ibbackup. We do 01193 not give the write permission to 01194 others because if one would succeed to 01195 start 2 instances of mysqld on the 01196 SAME files, that could cause severe 01197 database corruption! When opening 01198 raw disk partitions, Microsoft manuals 01199 say that we must give also the write 01200 permission. */ 01201 NULL, /* default security attributes */ 01202 create_flag, 01203 attributes, 01204 NULL); /* no template file */ 01205 01206 if (file == INVALID_HANDLE_VALUE) { 01207 *success = FALSE; 01208 01209 retry = os_file_handle_error(name, 01210 create_mode == OS_FILE_CREATE ? 01211 "create" : "open"); 01212 if (retry) { 01213 goto try_again; 01214 } 01215 } else { 01216 *success = TRUE; 01217 } 01218 01219 return(file); 01220 #else /* __WIN__ */ 01221 os_file_t file; 01222 int create_flag; 01223 ibool retry; 01224 const char* mode_str = NULL; 01225 const char* type_str = NULL; 01226 const char* purpose_str = NULL; 01227 01228 try_again: 01229 ut_a(name); 01230 01231 if (create_mode == OS_FILE_OPEN || create_mode == OS_FILE_OPEN_RAW 01232 || create_mode == OS_FILE_OPEN_RETRY) { 01233 mode_str = "OPEN"; 01234 create_flag = O_RDWR; 01235 } else if (create_mode == OS_FILE_CREATE) { 01236 mode_str = "CREATE"; 01237 create_flag = O_RDWR | O_CREAT | O_EXCL; 01238 } else if (create_mode == OS_FILE_OVERWRITE) { 01239 mode_str = "OVERWRITE"; 01240 create_flag = O_RDWR | O_CREAT | O_TRUNC; 01241 } else { 01242 create_flag = 0; 01243 ut_error; 01244 } 01245 01246 if (type == OS_LOG_FILE) { 01247 type_str = "LOG"; 01248 } else if (type == OS_DATA_FILE) { 01249 type_str = "DATA"; 01250 } else { 01251 ut_error; 01252 } 01253 01254 if (purpose == OS_FILE_AIO) { 01255 purpose_str = "AIO"; 01256 } else if (purpose == OS_FILE_NORMAL) { 01257 purpose_str = "NORMAL"; 01258 } else { 01259 ut_error; 01260 } 01261 01262 /* fprintf(stderr, "Opening file %s, mode %s, type %s, purpose %s\n", 01263 name, mode_str, type_str, purpose_str); */ 01264 #ifdef O_SYNC 01265 /* We let O_SYNC only affect log files; note that we map O_DSYNC to 01266 O_SYNC because the datasync options seemed to corrupt files in 2001 01267 in both Linux and Solaris */ 01268 if (type == OS_LOG_FILE 01269 && srv_unix_file_flush_method == SRV_UNIX_O_DSYNC) { 01270 01271 /* fprintf(stderr, "Using O_SYNC for file %s\n", name); */ 01272 01273 create_flag = create_flag | O_SYNC; 01274 } 01275 #endif 01276 #ifdef O_DIRECT 01277 /* We let O_DIRECT only affect data files */ 01278 if (type != OS_LOG_FILE 01279 && srv_unix_file_flush_method == SRV_UNIX_O_DIRECT) { 01280 01281 /* fprintf(stderr, "Using O_DIRECT for file %s\n", name); */ 01282 01283 create_flag = create_flag | O_DIRECT; 01284 } 01285 #endif 01286 if (create_mode == OS_FILE_CREATE) { 01287 file = open(name, create_flag, os_innodb_umask); 01288 } else { 01289 file = open(name, create_flag); 01290 } 01291 01292 if (file == -1) { 01293 *success = FALSE; 01294 01295 retry = os_file_handle_error(name, 01296 create_mode == OS_FILE_CREATE ? 01297 "create" : "open"); 01298 if (retry) { 01299 goto try_again; 01300 } 01301 #ifdef USE_FILE_LOCK 01302 } else if (create_mode != OS_FILE_OPEN_RAW 01303 && os_file_lock(file, name)) { 01304 *success = FALSE; 01305 if (create_mode == OS_FILE_OPEN_RETRY) { 01306 int i; 01307 ut_print_timestamp(stderr); 01308 fputs(" InnoDB: Retrying to lock the first data file\n", 01309 stderr); 01310 for (i = 0; i < 100; i++) { 01311 os_thread_sleep(1000000); 01312 if (!os_file_lock(file, name)) { 01313 *success = TRUE; 01314 return(file); 01315 } 01316 } 01317 ut_print_timestamp(stderr); 01318 fputs(" InnoDB: Unable to open the first data file\n", 01319 stderr); 01320 } 01321 close(file); 01322 file = -1; 01323 #endif 01324 } else { 01325 *success = TRUE; 01326 } 01327 01328 return(file); 01329 #endif /* __WIN__ */ 01330 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_file_create_directory | ( | const char * | pathname, | |
| ibool | fail_if_exists | |||
| ) |
Definition at line 805 of file os0file.c.
References errno, FALSE, NULL, os_file_handle_error(), and TRUE.
Referenced by fil_create_directory_for_tablename(), and os_file_create_subdirs_if_needed().
00807 : TRUE if call succeeds, 00808 FALSE on error */ 00809 const char* pathname, /* in: directory name as 00810 null-terminated string */ 00811 ibool fail_if_exists) /* in: if TRUE, pre-existing directory 00812 is treated as an error. */ 00813 { 00814 #ifdef __WIN__ 00815 BOOL rcode; 00816 00817 rcode = CreateDirectory((LPCTSTR) pathname, NULL); 00818 if (!(rcode != 0 || 00819 (GetLastError() == ERROR_ALREADY_EXISTS && !fail_if_exists))) { 00820 /* failure */ 00821 os_file_handle_error(pathname, "CreateDirectory"); 00822 00823 return(FALSE); 00824 } 00825 00826 return (TRUE); 00827 #else 00828 int rcode; 00829 00830 rcode = mkdir(pathname, 0770); 00831 00832 if (!(rcode == 0 || (errno == EEXIST && !fail_if_exists))) { 00833 /* failure */ 00834 os_file_handle_error(pathname, "mkdir"); 00835 00836 return(FALSE); 00837 } 00838 00839 return (TRUE); 00840 #endif 00841 }
Here is the call graph for this function:

Here is the caller graph for this function:

| os_file_t os_file_create_simple | ( | const char * | name, | |
| ulint | create_mode, | |||
| ulint | access_type, | |||
| ibool * | success | |||
| ) |
Definition at line 847 of file os0file.c.
References access, create_flag, FALSE, NULL, OS_FILE_CREATE, OS_FILE_CREATE_PATH, os_file_create_subdirs_if_needed(), os_file_handle_error(), os_file_lock(), OS_FILE_OPEN, OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, S_IRGRP, S_IRUSR, S_IWGRP, S_IWUSR, TRUE, ut_a, and ut_error.
00849 : handle to the file, not defined 00850 if error, error number can be retrieved with 00851 os_file_get_last_error */ 00852 const char* name, /* in: name of the file or path as a 00853 null-terminated string */ 00854 ulint create_mode,/* in: OS_FILE_OPEN if an existing file is 00855 opened (if does not exist, error), or 00856 OS_FILE_CREATE if a new file is created 00857 (if exists, error), or 00858 OS_FILE_CREATE_PATH if new file 00859 (if exists, error) and subdirectories along 00860 its path are created (if needed)*/ 00861 ulint access_type,/* in: OS_FILE_READ_ONLY or 00862 OS_FILE_READ_WRITE */ 00863 ibool* success)/* out: TRUE if succeed, FALSE if error */ 00864 { 00865 #ifdef __WIN__ 00866 os_file_t file; 00867 DWORD create_flag; 00868 DWORD access; 00869 DWORD attributes = 0; 00870 ibool retry; 00871 00872 try_again: 00873 ut_a(name); 00874 00875 if (create_mode == OS_FILE_OPEN) { 00876 create_flag = OPEN_EXISTING; 00877 } else if (create_mode == OS_FILE_CREATE) { 00878 create_flag = CREATE_NEW; 00879 } else if (create_mode == OS_FILE_CREATE_PATH) { 00880 /* create subdirs along the path if needed */ 00881 *success = os_file_create_subdirs_if_needed(name); 00882 if (!*success) { 00883 ut_error; 00884 } 00885 create_flag = CREATE_NEW; 00886 create_mode = OS_FILE_CREATE; 00887 } else { 00888 create_flag = 0; 00889 ut_error; 00890 } 00891 00892 if (access_type == OS_FILE_READ_ONLY) { 00893 access = GENERIC_READ; 00894 } else if (access_type == OS_FILE_READ_WRITE) { 00895 access = GENERIC_READ | GENERIC_WRITE; 00896 } else { 00897 access = 0; 00898 ut_error; 00899 } 00900 00901 file = CreateFile((LPCTSTR) name, 00902 access, 00903 FILE_SHARE_READ | FILE_SHARE_WRITE, 00904 /* file can be read ansd written also 00905 by other processes */ 00906 NULL, /* default security attributes */ 00907 create_flag, 00908 attributes, 00909 NULL); /* no template file */ 00910 00911 if (file == INVALID_HANDLE_VALUE) { 00912 *success = FALSE; 00913 00914 retry = os_file_handle_error(name, 00915 create_mode == OS_FILE_OPEN ? 00916 "open" : "create"); 00917 if (retry) { 00918 goto try_again; 00919 } 00920 } else { 00921 *success = TRUE; 00922 } 00923 00924 return(file); 00925 #else /* __WIN__ */ 00926 os_file_t file; 00927 int create_flag; 00928 ibool retry; 00929 00930 try_again: 00931 ut_a(name); 00932 00933 if (create_mode == OS_FILE_OPEN) { 00934 if (access_type == OS_FILE_READ_ONLY) { 00935 create_flag = O_RDONLY; 00936 } else { 00937 create_flag = O_RDWR; 00938 } 00939 } else if (create_mode == OS_FILE_CREATE) { 00940 create_flag = O_RDWR | O_CREAT | O_EXCL; 00941 } else if (create_mode == OS_FILE_CREATE_PATH) { 00942 /* create subdirs along the path if needed */ 00943 *success = os_file_create_subdirs_if_needed(name); 00944 if (!*success) { 00945 return (-1); 00946 } 00947 create_flag = O_RDWR | O_CREAT | O_EXCL; 00948 create_mode = OS_FILE_CREATE; 00949 } else { 00950 create_flag = 0; 00951 ut_error; 00952 } 00953 00954 if (create_mode == OS_FILE_CREATE) { 00955 file = open(name, create_flag, S_IRUSR | S_IWUSR 00956 | S_IRGRP | S_IWGRP); 00957 } else { 00958 file = open(name, create_flag); 00959 } 00960 00961 if (file == -1) { 00962 *success = FALSE; 00963 00964 retry = os_file_handle_error(name, 00965 create_mode == OS_FILE_OPEN ? 00966 "open" : "create"); 00967 if (retry) { 00968 goto try_again; 00969 } 00970 #ifdef USE_FILE_LOCK 00971 } else if (access_type == OS_FILE_READ_WRITE 00972 && os_file_lock(file, name)) { 00973 *success = FALSE; 00974 close(file); 00975 file = -1; 00976 #endif 00977 } else { 00978 *success = TRUE; 00979 } 00980 00981 return(file); 00982 #endif /* __WIN__ */ 00983 }
Here is the call graph for this function:

| os_file_t os_file_create_simple_no_error_handling | ( | const char * | name, | |
| ulint | create_mode, | |||
| ulint | access_type, | |||
| ibool * | success | |||
| ) |
Definition at line 989 of file os0file.c.
References access, create_flag, FALSE, FILE_SHARE_DELETE, NULL, OS_FILE_CREATE, os_file_lock(), OS_FILE_OPEN, OS_FILE_READ_ALLOW_DELETE, OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, S_IRGRP, S_IRUSR, S_IWGRP, S_IWUSR, TRUE, ut_a, and ut_error.
Referenced by fil_load_single_table_tablespace(), fil_node_open_file(), fil_open_single_table_tablespace(), and fil_reset_too_high_lsns().
00991 : handle to the file, not defined 00992 if error, error number can be retrieved with 00993 os_file_get_last_error */ 00994 const char* name, /* in: name of the file or path as a 00995 null-terminated string */ 00996 ulint create_mode,/* in: OS_FILE_OPEN if an existing file 00997 is opened (if does not exist, error), or 00998 OS_FILE_CREATE if a new file is created 00999 (if exists, error) */ 01000 ulint access_type,/* in: OS_FILE_READ_ONLY, 01001 OS_FILE_READ_WRITE, or 01002 OS_FILE_READ_ALLOW_DELETE; the last option is 01003 used by a backup program reading the file */ 01004 ibool* success)/* out: TRUE if succeed, FALSE if error */ 01005 { 01006 #ifdef __WIN__ 01007 os_file_t file; 01008 DWORD create_flag; 01009 DWORD access; 01010 DWORD attributes = 0; 01011 DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE; 01012 01013 ut_a(name); 01014 01015 if (create_mode == OS_FILE_OPEN) { 01016 create_flag = OPEN_EXISTING; 01017 } else if (create_mode == OS_FILE_CREATE) { 01018 create_flag = CREATE_NEW; 01019 } else { 01020 create_flag = 0; 01021 ut_error; 01022 } 01023 01024 if (access_type == OS_FILE_READ_ONLY) { 01025 access = GENERIC_READ; 01026 } else if (access_type == OS_FILE_READ_WRITE) { 01027 access = GENERIC_READ | GENERIC_WRITE; 01028 } else if (access_type == OS_FILE_READ_ALLOW_DELETE) { 01029 access = GENERIC_READ; 01030 share_mode = FILE_SHARE_DELETE | FILE_SHARE_READ 01031 | FILE_SHARE_WRITE; /* A backup program has to give 01032 mysqld the maximum freedom to 01033 do what it likes with the 01034 file */ 01035 } else { 01036 access = 0; 01037 ut_error; 01038 } 01039 01040 file = CreateFile((LPCTSTR) name, 01041 access, 01042 share_mode, 01043 NULL, /* default security attributes */ 01044 create_flag, 01045 attributes, 01046 NULL); /* no template file */ 01047 01048 if (file == INVALID_HANDLE_VALUE) { 01049 *success = FALSE; 01050 } else { 01051 *success = TRUE; 01052 } 01053 01054 return(file); 01055 #else /* __WIN__ */ 01056 os_file_t file; 01057 int create_flag; 01058 01059 ut_a(name); 01060 01061 if (create_mode == OS_FILE_OPEN) { 01062 if (access_type == OS_FILE_READ_ONLY) { 01063 create_flag = O_RDONLY; 01064 } else { 01065 create_flag = O_RDWR; 01066 } 01067 } else if (create_mode == OS_FILE_CREATE) { 01068 create_flag = O_RDWR | O_CREAT | O_EXCL; 01069 } else { 01070 create_flag = 0; 01071 ut_error; 01072 } 01073 01074 if (create_mode == OS_FILE_CREATE) { 01075 file = open(name, create_flag, S_IRUSR | S_IWUSR 01076 | S_IRGRP | S_IWGRP); 01077 } else { 01078 file = open(name, create_flag); 01079 } 01080 01081 if (file == -1) { 01082 *success = FALSE; 01083 #ifdef USE_FILE_LOCK 01084 } else if (access_type == OS_FILE_READ_WRITE 01085 && os_file_lock(file, name)) { 01086 *success = FALSE; 01087 close(file); 01088 file = -1; 01089 #endif 01090 } else { 01091 *success = TRUE; 01092 } 01093 01094 return(file); 01095 #endif /* __WIN__ */ 01096 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_file_create_subdirs_if_needed | ( | const char * | path | ) |
Definition at line 2672 of file os0file.c.
References FALSE, mem_free, os_file_create_directory(), os_file_create_subdirs_if_needed(), os_file_dirname(), OS_FILE_PATH_SEPARATOR, os_file_status(), strlen(), and TRUE.
Referenced by os_file_create_simple(), and os_file_create_subdirs_if_needed().
02674 : TRUE if call succeeded 02675 FALSE otherwise */ 02676 const char* path) /* in: path name */ 02677 { 02678 char* subdir; 02679 ibool success, subdir_exists; 02680 os_file_type_t type; 02681 02682 subdir = os_file_dirname(path); 02683 if (strlen(subdir) == 1 02684 && (*subdir == OS_FILE_PATH_SEPARATOR || *subdir == '.')) { 02685 /* subdir is root or cwd, nothing to do */ 02686 mem_free(subdir); 02687 02688 return(TRUE); 02689 } 02690 02691 /* Test if subdir exists */ 02692 success = os_file_status(subdir, &subdir_exists, &type); 02693 if (success && !subdir_exists) { 02694 /* subdir does not exist, create it */ 02695 success = os_file_create_subdirs_if_needed(subdir); 02696 if (!success) { 02697 mem_free(subdir); 02698 02699 return(FALSE); 02700 } 02701 success = os_file_create_directory(subdir, FALSE); 02702 } 02703 02704 mem_free(subdir); 02705 02706 return(success); 02707 }
Here is the call graph for this function:

Here is the caller graph for this function:

| FILE* os_file_create_tmpfile | ( | void | ) |
Definition at line 521 of file os0file.c.
References errno, innobase_mysql_tmpfile(), NULL, ut_error, and ut_print_timestamp().
Referenced by dict_init(), innobase_start_or_create_for_mysql(), and lock_sys_create().
00523 : temporary file handle, or NULL on error */ 00524 { 00525 #ifdef UNIV_HOTBACKUP 00526 ut_error; 00527 00528 return(NULL); 00529 #else 00530 # ifdef __NETWARE__ 00531 FILE* file = tmpfile(); 00532 # else /* __NETWARE__ */ 00533 FILE* file = NULL; 00534 int fd = innobase_mysql_tmpfile(); 00535 00536 if (fd >= 0) { 00537 file = fdopen(fd, "w+b"); 00538 } 00539 # endif /* __NETWARE__ */ 00540 00541 if (!file) { 00542 ut_print_timestamp(stderr); 00543 fprintf(stderr, 00544 " InnoDB: Error: unable to create temporary file;" 00545 " errno: %d\n", errno); 00546 # ifndef __NETWARE__ 00547 if (fd >= 0) { 00548 close(fd); 00549 } 00550 # endif /* !__NETWARE__ */ 00551 } 00552 00553 return(file); 00554 #endif /* UNIV_HOTBACKUP */ 00555 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_file_delete | ( | const char * | name | ) |
Definition at line 1397 of file os0file.c.
References count, FALSE, os_file_get_last_error(), os_file_handle_error_no_exit(), os_thread_sleep(), and TRUE.
Referenced by fil_create_new_single_table_tablespace(), and fil_delete_tablespace().
01399 : TRUE if success */ 01400 const char* name) /* in: file path as a null-terminated string */ 01401 { 01402 #ifdef __WIN__ 01403 BOOL ret; 01404 ulint count = 0; 01405 loop: 01406 /* In Windows, deleting an .ibd file may fail if ibbackup is copying 01407 it */ 01408 01409 ret = DeleteFile((LPCTSTR)name); 01410 01411 if (ret) { 01412 return(TRUE); 01413 } 01414 01415 if (GetLastError() == ERROR_FILE_NOT_FOUND) { 01416 /* If the file does not exist, we classify this as a 'mild' 01417 error and return */ 01418 01419 return(FALSE); 01420 } 01421 01422 count++; 01423 01424 if (count > 100 && 0 == (count % 10)) { 01425 fprintf(stderr, 01426 "InnoDB: Warning: cannot delete file %s\n" 01427 "InnoDB: Are you running ibbackup to back up the file?\n", name); 01428 01429 os_file_get_last_error(TRUE); /* print error information */ 01430 } 01431 01432 os_thread_sleep(1000000); /* sleep for a second */ 01433 01434 if (count > 2000) { 01435 01436 return(FALSE); 01437 } 01438 01439 goto loop; 01440 #else 01441 int ret; 01442 01443 ret = unlink((const char*)name); 01444 01445 if (ret != 0) { 01446 os_file_handle_error_no_exit(name, "delete"); 01447 01448 return(FALSE); 01449 } 01450 01451 return(TRUE); 01452 #endif 01453 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_file_delete_if_exists | ( | const char * | name | ) |
Definition at line 1336 of file os0file.c.
References count, errno, FALSE, os_file_get_last_error(), os_file_handle_error_no_exit(), os_thread_sleep(), and TRUE.
Referenced by fil_delete_tablespace().
01338 : TRUE if success */ 01339 const char* name) /* in: file path as a null-terminated string */ 01340 { 01341 #ifdef __WIN__ 01342 BOOL ret; 01343 ulint count = 0; 01344 loop: 01345 /* In Windows, deleting an .ibd file may fail if ibbackup is copying 01346 it */ 01347 01348 ret = DeleteFile((LPCTSTR)name); 01349 01350 if (ret) { 01351 return(TRUE); 01352 } 01353 01354 if (GetLastError() == ERROR_FILE_NOT_FOUND) { 01355 /* the file does not exist, this not an error */ 01356 01357 return(TRUE); 01358 } 01359 01360 count++; 01361 01362 if (count > 100 && 0 == (count % 10)) { 01363 fprintf(stderr, 01364 "InnoDB: Warning: cannot delete file %s\n" 01365 "InnoDB: Are you running ibbackup to back up the file?\n", name); 01366 01367 os_file_get_last_error(TRUE); /* print error information */ 01368 } 01369 01370 os_thread_sleep(1000000); /* sleep for a second */ 01371 01372 if (count > 2000) { 01373 01374 return(FALSE); 01375 } 01376 01377 goto loop; 01378 #else 01379 int ret; 01380 01381 ret = unlink((const char*)name); 01382 01383 if (ret != 0 && errno != ENOENT) { 01384 os_file_handle_error_no_exit(name, "delete"); 01385 01386 return(FALSE); 01387 } 01388 01389 return(TRUE); 01390 #endif 01391 }
Here is the call graph for this function:

Here is the caller graph for this function:

| char* os_file_dirname | ( | const char * | path | ) |
Definition at line 2641 of file os0file.c.
References mem_strdup(), mem_strdupl(), OS_FILE_PATH_SEPARATOR, and strrchr().
Referenced by os_file_create_subdirs_if_needed().
02643 : directory component of the 02644 pathname */ 02645 const char* path) /* in: pathname */ 02646 { 02647 /* Find the offset of the last slash */ 02648 const char* last_slash = strrchr(path, OS_FILE_PATH_SEPARATOR); 02649 if (!last_slash) { 02650 /* No slash in the path, return "." */ 02651 02652 return(mem_strdup(".")); 02653 } 02654 02655 /* Ok, there is a slash */ 02656 02657 if (last_slash == path) { 02658 /* last slash is the first char of the path */ 02659 02660 return(mem_strdup("/")); 02661 } 02662 02663 /* Non-trivial directory component */ 02664 02665 return(mem_strdupl(path, last_slash - path)); 02666 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_file_flush | ( | os_file_t | file | ) |
Definition at line 1749 of file os0file.c.
References errno, FALSE, NULL, os_file_handle_error(), os_n_fsyncs, srv_start_raw_disk_in_use, TRUE, ut_a, ut_error, and ut_print_timestamp().
Referenced by fil_create_new_single_table_tablespace(), fil_flush(), fil_reset_too_high_lsns(), os_file_pwrite(), os_file_set_size(), and os_file_write().
01751 : TRUE if success */ 01752 os_file_t file) /* in, own: handle to a file */ 01753 { 01754 #ifdef __WIN__ 01755 BOOL ret; 01756 01757 ut_a(file); 01758 01759 os_n_fsyncs++; 01760 01761 ret = FlushFileBuffers(file); 01762 01763 if (ret) { 01764 return(TRUE); 01765 } 01766 01767 /* Since Windows returns ERROR_INVALID_FUNCTION if the 'file' is 01768 actually a raw device, we choose to ignore that error if we are using 01769 raw disks */ 01770 01771 if (srv_start_raw_disk_in_use && GetLastError() 01772 == ERROR_INVALID_FUNCTION) { 01773 return(TRUE); 01774 } 01775 01776 os_file_handle_error(NULL, "flush"); 01777 01778 /* It is a fatal error if a file flush does not succeed, because then 01779 the database can get corrupt on disk */ 01780 ut_error; 01781 01782 return(FALSE); 01783 #else 01784 int ret; 01785 01786 #if defined(HAVE_DARWIN_THREADS) 01787 # ifndef F_FULLFSYNC 01788 /* The following definition is from the Mac OS X 10.3 <sys/fcntl.h> */ 01789 # define F_FULLFSYNC 51 /* fsync + ask the drive to flush to the media */ 01790 # elif F_FULLFSYNC != 51 01791 # error "F_FULLFSYNC != 51: ABI incompatibility with Mac OS X 10.3" 01792 # endif 01793 /* Apple has disabled fsync() for internal disk drives in OS X. That 01794 caused corruption for a user when he tested a power outage. Let us in 01795 OS X use a nonstandard flush method recommended by an Apple 01796 engineer. */ 01797 01798 if (!srv_have_fullfsync) { 01799 /* If we are not on an operating system that supports this, 01800 then fall back to a plain fsync. */ 01801 01802 ret = fsync(file); 01803 } else { 01804 ret = fcntl(file, F_FULLFSYNC, NULL); 01805 01806 if (ret) { 01807 /* If we are not on a file system that supports this, 01808 then fall back to a plain fsync. */ 01809 ret = fsync(file); 01810 } 01811 } 01812 #elif HAVE_FDATASYNC 01813 ret = fdatasync(file); 01814 #else 01815 /* fprintf(stderr, "Flushing to file %p\n", file); */ 01816 ret = fsync(file); 01817 #endif 01818 os_n_fsyncs++; 01819 01820 if (ret == 0) { 01821 return(TRUE); 01822 } 01823 01824 /* Since Linux returns EINVAL if the 'file' is actually a raw device, 01825 we choose to ignore that error if we are using raw disks */ 01826 01827 if (srv_start_raw_disk_in_use && errno == EINVAL) { 01828 01829 return(TRUE); 01830 } 01831 01832 ut_print_timestamp(stderr); 01833 01834 fprintf(stderr, 01835 " InnoDB: Error: the OS said file flush did not succeed\n"); 01836 01837 os_file_handle_error(NULL, "flush"); 01838 01839 /* It is a fatal error if a file flush does not succeed, because then 01840 the database can get corrupt on disk */ 01841 ut_error; 01842 01843 return(FALSE); 01844 #endif 01845 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ulint os_file_get_last_error | ( | ibool | report_all_errors | ) |
Definition at line 213 of file os0file.c.
References err, errno, NULL, OS_FILE_AIO_RESOURCES_RESERVED, OS_FILE_ALREADY_EXISTS, OS_FILE_DISK_FULL, OS_FILE_NOT_FOUND, OS_FILE_PATH_ERROR, srv_is_being_started, and ut_print_timestamp().
Referenced by fil_create_new_single_table_tablespace(), fil_load_single_table_tablespace(), fil_node_open_file(), fil_open_single_table_tablespace(), fil_reset_too_high_lsns(), open_or_create_data_files(), open_or_create_log_file(), os_file_delete(), os_file_delete_if_exists(), os_file_handle_error(), and os_file_handle_error_no_exit().
00215 : error number, or OS error 00216 number + 100 */ 00217 ibool report_all_errors) /* in: TRUE if we want an error message 00218 printed of all errors */ 00219 { 00220 ulint err; 00221 00222 #ifdef __WIN__ 00223 00224 err = (ulint) GetLastError(); 00225 00226 if (report_all_errors 00227 || (err != ERROR_DISK_FULL && err != ERROR_FILE_EXISTS)) { 00228 00229 ut_print_timestamp(stderr); 00230 fprintf(stderr, 00231 " InnoDB: Operating system error number %lu in a file operation.\n", (ulong) err); 00232 00233 if (err == ERROR_PATH_NOT_FOUND) { 00234 fprintf(stderr, 00235 "InnoDB: The error means the system cannot find the path specified.\n"); 00236 00237 if (srv_is_being_started) { 00238 fprintf(stderr, 00239 "InnoDB: If you are installing InnoDB, remember that you must create\n" 00240 "InnoDB: directories yourself, InnoDB does not create them.\n"); 00241 } 00242 } else if (err == ERROR_ACCESS_DENIED) { 00243 fprintf(stderr, 00244 "InnoDB: The error means mysqld does not have the access rights to\n" 00245 "InnoDB: the directory. It may also be you have created a subdirectory\n" 00246 "InnoDB: of the same name as a data file.\n"); 00247 } else { 00248 fprintf(stderr, 00249 "InnoDB: Some operating system error numbers are described at\n" 00250 "InnoDB: " 00251 "http://dev.mysql.com/doc/mysql/en/Operating_System_error_codes.html\n"); 00252 } 00253 } 00254 00255 fflush(stderr); 00256 00257 if (err == ERROR_FILE_NOT_FOUND) { 00258 return(OS_FILE_NOT_FOUND); 00259 } else if (err == ERROR_DISK_FULL) { 00260 return(OS_FILE_DISK_FULL); 00261 } else if (err == ERROR_FILE_EXISTS) { 00262 return(OS_FILE_ALREADY_EXISTS); 00263 } else { 00264 return(100 + err); 00265 } 00266 #else 00267 err = (ulint) errno; 00268 00269 if (report_all_errors 00270 || (err != ENOSPC && err != EEXIST)) { 00271 00272 ut_print_timestamp(stderr); 00273 fprintf(stderr, 00274 " InnoDB: Operating system error number %lu in a file operation.\n", (ulong) err); 00275 00276 if (err == ENOENT) { 00277 fprintf(stderr, 00278 "InnoDB: The error means the system cannot find the path specified.\n"); 00279 00280 if (srv_is_being_started) { 00281 fprintf(stderr, 00282 "InnoDB: If you are installing InnoDB, remember that you must create\n" 00283 "InnoDB: directories yourself, InnoDB does not create them.\n"); 00284 } 00285 } else if (err == EACCES) { 00286 fprintf(stderr, 00287 "InnoDB: The error means mysqld does not have the access rights to\n" 00288 "InnoDB: the directory.\n"); 00289 } else { 00290 if (strerror((int)err) != NULL) { 00291 fprintf(stderr, 00292 "InnoDB: Error number %lu means '%s'.\n", err, strerror((int)err)); 00293 } 00294 00295 fprintf(stderr, 00296 "InnoDB: Some operating system error numbers are described at\n" 00297 "InnoDB: " 00298 "http://dev.mysql.com/doc/mysql/en/Operating_System_error_codes.html\n"); 00299 } 00300 } 00301 00302 fflush(stderr); 00303 00304 if (err == ENOSPC ) { 00305 return(OS_FILE_DISK_FULL); 00306 #ifdef POSIX_ASYNC_IO 00307 } else if (err == EAGAIN) { 00308 return(OS_FILE_AIO_RESOURCES_RESERVED); 00309 #endif 00310 } else if (err == ENOENT) { 00311 return(OS_FILE_NOT_FOUND); 00312 } else if (err == EEXIST) { 00313 return(OS_FILE_ALREADY_EXISTS); 00314 } else if (err == EXDEV || err == ENOTDIR || err == EISDIR) { 00315 return(OS_FILE_PATH_ERROR); 00316 } else { 00317 return(100 + err); 00318 } 00319 #endif 00320 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1572 of file os0file.c.
References FALSE, lseek, TaoCrypt::NO_ERROR, off_t, SEEK_END, and TRUE.
Referenced by fil_load_single_table_tablespace(), fil_node_open_file(), open_or_create_data_files(), open_or_create_log_file(), and os_file_get_size_as_iblonglong().
01574 : TRUE if success */ 01575 os_file_t file, /* in: handle to a file */ 01576 ulint* size, /* out: least significant 32 bits of file 01577 size */ 01578 ulint* size_high)/* out: most significant 32 bits of size */ 01579 { 01580 #ifdef __WIN__ 01581 DWORD high; 01582 DWORD low; 01583 01584 low = GetFileSize(file, &high); 01585 01586 if ((low == 0xFFFFFFFF) && (GetLastError() != NO_ERROR)) { 01587 return(FALSE); 01588 } 01589 01590 *size = low; 01591 *size_high = high; 01592 01593 return(TRUE); 01594 #else 01595 off_t offs; 01596 01597 offs = lseek(file, 0, SEEK_END); 01598 01599 if (offs == ((off_t)-1)) { 01600 01601 return(FALSE); 01602 } 01603 01604 if (sizeof(off_t) > 4) { 01605 *size = (ulint)(offs & 0xFFFFFFFFUL); 01606 *size_high = (ulint)(offs >> 32); 01607 } else { 01608 *size = (ulint) offs; 01609 *size_high = 0; 01610 } 01611 01612 return(TRUE); 01613 #endif 01614 }
Here is the caller graph for this function:

| ib_longlong os_file_get_size_as_iblonglong | ( | os_file_t | file | ) |
Definition at line 1620 of file os0file.c.
References os_file_get_size().
Referenced by fil_extend_space_to_desired_size(), and fil_reset_too_high_lsns().
01622 : size in bytes, -1 if error */ 01623 os_file_t file) /* in: handle to a file */ 01624 { 01625 ulint size; 01626 ulint size_high; 01627 ibool success; 01628 01629 success = os_file_get_size(file, &size, &size_high); 01630 01631 if (!success) { 01632 01633 return(-1); 01634 } 01635 01636 return((((ib_longlong)size_high) << 32) + (ib_longlong)size); 01637 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_file_get_status | ( | const char * | path, | |
| os_file_stat_t * | stat_info | |||
| ) |
Definition at line 2532 of file os0file.c.
References os_file_stat_struct::atime, os_file_stat_struct::ctime, errno, FALSE, os_file_stat_struct::mtime, os_file_handle_error_no_exit(), OS_FILE_TYPE_DIR, OS_FILE_TYPE_FILE, OS_FILE_TYPE_LINK, OS_FILE_TYPE_UNKNOWN, S_ISDIR, S_ISLNK, os_file_stat_struct::size, TRUE, and os_file_stat_struct::type.
02534 : TRUE if stat information found */ 02535 const char* path, /* in: pathname of the file */ 02536 os_file_stat_t* stat_info) /* information of a file in a directory */ 02537 { 02538 #ifdef __WIN__ 02539 int ret; 02540 struct _stat statinfo; 02541 02542 ret = _stat(path, &statinfo); 02543 if (ret && (errno == ENOENT || errno == ENOTDIR)) { 02544 /* file does not exist */ 02545 02546 return(FALSE); 02547 } else if (ret) { 02548 /* file exists, but stat call failed */ 02549 02550 os_file_handle_error_no_exit(path, "stat"); 02551 02552 return(FALSE); 02553 } 02554 if (_S_IFDIR & statinfo.st_mode) { 02555 stat_info->type = OS_FILE_TYPE_DIR; 02556 } else if (_S_IFREG & statinfo.st_mode) { 02557 stat_info->type = OS_FILE_TYPE_FILE; 02558 } else { 02559 stat_info->type = OS_FILE_TYPE_UNKNOWN; 02560 } 02561 02562 stat_info->ctime = statinfo.st_ctime; 02563 stat_info->atime = statinfo.st_atime; 02564 stat_info->mtime = statinfo.st_mtime; 02565 stat_info->size = statinfo.st_size; 02566 02567 return(TRUE); 02568 #else 02569 int ret; 02570 struct stat statinfo; 02571 02572 ret = stat(path, &statinfo); 02573 02574 if (ret && (errno == ENOENT || errno == ENOTDIR)) { 02575 /* file does not exist */ 02576 02577 return(FALSE); 02578 } else if (ret) { 02579 /* file exists, but stat call failed */ 02580 02581 os_file_handle_error_no_exit(path, "stat"); 02582 02583 return(FALSE); 02584 } 02585 02586 if (S_ISDIR(statinfo.st_mode)) { 02587 stat_info->type = OS_FILE_TYPE_DIR; 02588 } else if (S_ISLNK(statinfo.st_mode)) { 02589 stat_info->type = OS_FILE_TYPE_LINK; 02590 } else if (S_ISREG(statinfo.st_mode)) { 02591 stat_info->type = OS_FILE_TYPE_FILE; 02592 } else { 02593 stat_info->type = OS_FILE_TYPE_UNKNOWN; 02594 } 02595 02596 stat_info->ctime = statinfo.st_ctime; 02597 stat_info->atime = statinfo.st_atime; 02598 stat_info->mtime = statinfo.st_mtime; 02599 stat_info->size = statinfo.st_size; 02600 02601 return(TRUE); 02602 #endif 02603 }
Here is the call graph for this function:

| os_file_dir_t os_file_opendir | ( | const char * | dirname, | |
| ibool | error_is_fatal | |||
| ) |
Definition at line 564 of file os0file.c.
References NULL, os_file_handle_error(), OS_FILE_MAX_PATH, path, strlen(), ut_a, ut_free(), and ut_malloc().
Referenced by fil_load_single_table_tablespaces().
00566 : directory stream, NULL if 00567 error */ 00568 const char* dirname, /* in: directory name; it must not 00569 contain a trailing '\' or '/' */ 00570 ibool error_is_fatal) /* in: TRUE if we should treat an 00571 error as a fatal error; if we try to 00572 open symlinks then we do not wish a 00573 fatal error if it happens not to be 00574 a directory */ 00575 { 00576 os_file_dir_t dir; 00577 #ifdef __WIN__ 00578 LPWIN32_FIND_DATA lpFindFileData; 00579 char path[OS_FILE_MAX_PATH + 3]; 00580 00581 ut_a(strlen(dirname) < OS_FILE_MAX_PATH); 00582 00583 strcpy(path, dirname); 00584 strcpy(path + strlen(path), "\\*"); 00585 00586 /* Note that in Windows opening the 'directory stream' also retrieves 00587 the first entry in the directory. Since it is '.', that is no problem, 00588 as we will skip over the '.' and '..' entries anyway. */ 00589 00590 lpFindFileData = ut_malloc(sizeof(WIN32_FIND_DATA)); 00591 00592 dir = FindFirstFile((LPCTSTR) path, lpFindFileData); 00593 00594 ut_free(lpFindFileData); 00595 00596 if (dir == INVALID_HANDLE_VALUE) { 00597 00598 if (error_is_fatal) { 00599 os_file_handle_error(dirname, "opendir"); 00600 } 00601 00602 return(NULL); 00603 } 00604 00605 return(dir); 00606 #else 00607 dir = opendir(dirname); 00608 00609 if (dir == NULL && error_is_fatal) { 00610 os_file_handle_error(dirname, "opendir"); 00611 } 00612 00613 return(dir); 00614 #endif 00615 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2050 of file os0file.c.
References __WIN__, errno, FALSE, TaoCrypt::NO_ERROR, NULL, os_bytes_read_since_printout, os_file_count_mutex, os_file_handle_error(), OS_FILE_N_SEEK_MUTEXES, os_file_pread(), os_file_seek_mutexes, os_mutex_enter(), os_mutex_exit(), os_n_file_reads, os_n_pending_reads, TRUE, ut_a, ut_ad, and ut_error.
Referenced by fil_load_single_table_tablespace(), fil_node_open_file(), fil_open_single_table_tablespace(), fil_read_flushed_lsn_and_arch_log_no(), fil_reset_too_high_lsns(), and os_aio().
02052 : TRUE if request was 02053 successful, FALSE if fail */ 02054 os_file_t file, /* in: handle to a file */ 02055 void* buf, /* in: buffer where to read */ 02056 ulint offset, /* in: least significant 32 bits of file 02057 offset where to read */ 02058 ulint offset_high, /* in: most significant 32 bits of 02059 offset */ 02060 ulint n) /* in: number of bytes to read */ 02061 { 02062 #ifdef __WIN__ 02063 BOOL ret; 02064 DWORD len; 02065 DWORD ret2; 02066 DWORD low; 02067 DWORD high; 02068 ibool retry; 02069 ulint i; 02070 02071 ut_a((offset & 0xFFFFFFFFUL) == offset); 02072 02073 os_n_file_reads++; 02074 os_bytes_read_since_printout += n; 02075 02076 try_again: 02077 ut_ad(file); 02078 ut_ad(buf); 02079 ut_ad(n > 0); 02080 02081 low = (DWORD) offset; 02082 high = (DWORD) offset_high; 02083 02084 os_mutex_enter(os_file_count_mutex); 02085 os_n_pending_reads++; 02086 os_mutex_exit(os_file_count_mutex); 02087 02088 /* Protect the seek / read operation with a mutex */ 02089 i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES; 02090 02091 os_mutex_enter(os_file_seek_mutexes[i]); 02092 02093 ret2 = SetFilePointer(file, low, &high, FILE_BEGIN); 02094 02095 if (ret2 == 0xFFFFFFFF && GetLastError() != NO_ERROR) { 02096 02097 os_mutex_exit(os_file_seek_mutexes[i]); 02098 02099 os_mutex_enter(os_file_count_mutex); 02100 os_n_pending_reads--; 02101 os_mutex_exit(os_file_count_mutex); 02102 02103 goto error_handling; 02104 } 02105 02106 ret = ReadFile(file, buf, (DWORD) n, &len, NULL); 02107 02108 os_mutex_exit(os_file_seek_mutexes[i]); 02109 02110 os_mutex_enter(os_file_count_mutex); 02111 os_n_pending_reads--; 02112 os_mutex_exit(os_file_count_mutex); 02113 02114 if (ret && len == n) { 02115 return(TRUE); 02116 } 02117 #else 02118 ibool retry; 02119 ssize_t ret; 02120 02121 os_bytes_read_since_printout += n; 02122 02123 try_again: 02124 ret = os_file_pread(file, buf, n, offset, offset_high); 02125 02126 if ((ulint)ret == n) { 02127 02128 return(TRUE); 02129 } 02130 02131 fprintf(stderr, 02132 "InnoDB: Error: tried to read %lu bytes at offset %lu %lu.\n" 02133 "InnoDB: Was only able to read %ld.\n", (ulong)n, (ulong)offset_high, 02134 (ulong)offset, (long)ret); 02135 #endif 02136 #ifdef __WIN__ 02137 error_handling: 02138 #endif 02139 retry = os_file_handle_error(NULL, "read"); 02140 02141 if (retry) { 02142 goto try_again; 02143 } 02144 02145 fprintf(stderr, 02146 "InnoDB: Fatal error: cannot read from file. OS error number %lu.\n", 02147 #ifdef __WIN__ 02148 (ulong) GetLastError() 02149 #else 02150 (ulong) errno 02151 #endif 02152 ); 02153 fflush(stderr); 02154 02155 ut_error; 02156 02157 return(FALSE); 02158 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_file_read_no_error_handling | ( | os_file_t | file, | |
| void * | buf, | |||
| ulint | offset, | |||
| ulint | offset_high, | |||
| ulint | n | |||
| ) |
Definition at line 2165 of file os0file.c.
References FALSE, TaoCrypt::NO_ERROR, NULL, os_bytes_read_since_printout, os_file_count_mutex, os_file_handle_error_no_exit(), OS_FILE_N_SEEK_MUTEXES, os_file_pread(), os_file_seek_mutexes, os_mutex_enter(), os_mutex_exit(), os_n_file_reads, os_n_pending_reads, TRUE, ut_a, and ut_ad.
02167 : TRUE if request was 02168 successful, FALSE if fail */ 02169 os_file_t file, /* in: handle to a file */ 02170 void* buf, /* in: buffer where to read */ 02171 ulint offset, /* in: least significant 32 bits of file 02172 offset where to read */ 02173 ulint offset_high, /* in: most significant 32 bits of 02174 offset */ 02175 ulint n) /* in: number of bytes to read */ 02176 { 02177 #ifdef __WIN__ 02178 BOOL ret; 02179 DWORD len; 02180 DWORD ret2; 02181 DWORD low; 02182 DWORD high; 02183 ibool retry; 02184 ulint i; 02185 02186 ut_a((offset & 0xFFFFFFFFUL) == offset); 02187 02188 os_n_file_reads++; 02189 os_bytes_read_since_printout += n; 02190 02191 try_again: 02192 ut_ad(file); 02193 ut_ad(buf); 02194 ut_ad(n > 0); 02195 02196 low = (DWORD) offset; 02197 high = (DWORD) offset_high; 02198 02199 os_mutex_enter(os_file_count_mutex); 02200 os_n_pending_reads++; 02201 os_mutex_exit(os_file_count_mutex); 02202 02203 /* Protect the seek / read operation with a mutex */ 02204 i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES; 02205 02206 os_mutex_enter(os_file_seek_mutexes[i]); 02207 02208 ret2 = SetFilePointer(file, low, &high, FILE_BEGIN); 02209 02210 if (ret2 == 0xFFFFFFFF && GetLastError() != NO_ERROR) { 02211 02212 os_mutex_exit(os_file_seek_mutexes[i]); 02213 02214 os_mutex_enter(os_file_count_mutex); 02215 os_n_pending_reads--; 02216 os_mutex_exit(os_file_count_mutex); 02217 02218 goto error_handling; 02219 } 02220 02221 ret = ReadFile(file, buf, (DWORD) n, &len, NULL); 02222 02223 os_mutex_exit(os_file_seek_mutexes[i]); 02224 02225 os_mutex_enter(os_file_count_mutex); 02226 os_n_pending_reads--; 02227 os_mutex_exit(os_file_count_mutex); 02228 02229 if (ret && len == n) { 02230 return(TRUE); 02231 } 02232 #else 02233 ibool retry; 02234 ssize_t ret; 02235 02236 os_bytes_read_since_printout += n; 02237 02238 try_again: 02239 ret = os_file_pread(file, buf, n, offset, offset_high); 02240 02241 if ((ulint)ret == n) { 02242 02243 return(TRUE); 02244 } 02245 #endif 02246 #ifdef __WIN__ 02247 error_handling: 02248 #endif 02249 retry = os_file_handle_error_no_exit(NULL, "read"); 02250 02251 if (retry) { 02252 goto try_again; 02253 } 02254 02255 return(FALSE); 02256 }
Here is the call graph for this function:

| void os_file_read_string | ( | FILE * | file, | |
| char * | str, | |||
| ulint | size | |||
| ) |
Definition at line 2264 of file os0file.c.
Referenced by trx_set_detailed_error_from_file().
02266 : file to read from */ 02267 char* str, /* in: buffer where to read */ 02268 ulint size) /* in: size of buffer */ 02269 { 02270 size_t flen; 02271 02272 if (size == 0) { 02273 return; 02274 } 02275 02276 rewind(file); 02277 flen = fread(str, 1, size - 1, file); 02278 str[flen] = '\0'; 02279 }
Here is the caller graph for this function:

| int os_file_readdir_next_file | ( | const char * | dirname, | |
| os_file_dir_t | dir, | |||
| os_file_stat_t * | info | |||
| ) |
Definition at line 656 of file os0file.c.
References dirent, os_file_stat_struct::name, NULL, os_file_handle_error_no_exit(), OS_FILE_MAX_PATH, OS_FILE_TYPE_DIR, OS_FILE_TYPE_FILE, OS_FILE_TYPE_LINK, OS_FILE_TYPE_UNKNOWN, S_ISDIR, S_ISLNK, os_file_stat_struct::size, strcmp(), strlen(), os_file_stat_struct::type, ut_a, ut_free(), and ut_malloc().
Referenced by fil_file_readdir_next_file().
00658 : 0 if ok, -1 if error, 1 if at the end 00659 of the directory */ 00660 const char* dirname,/* in: directory name or path */ 00661 os_file_dir_t dir, /* in: directory stream */ 00662 os_file_stat_t* info) /* in/out: buffer where the info is returned */ 00663 { 00664 #ifdef __WIN__ 00665 LPWIN32_FIND_DATA lpFindFileData; 00666 BOOL ret; 00667 00668 lpFindFileData = ut_malloc(sizeof(WIN32_FIND_DATA)); 00669 next_file: 00670 ret = FindNextFile(dir, lpFindFileData); 00671 00672 if (ret) { 00673 ut_a(strlen((char *) lpFindFileData->cFileName) < OS_FILE_MAX_PATH); 00674 00675 if (strcmp((char *) lpFindFileData->cFileName, ".") == 0 00676 || strcmp((char *) lpFindFileData->cFileName, "..") == 0) { 00677 00678 goto next_file; 00679 } 00680 00681 strcpy(info->name, (char *) lpFindFileData->cFileName); 00682 00683 info->size = (ib_longlong)(lpFindFileData->nFileSizeLow) 00684 + (((ib_longlong)(lpFindFileData->nFileSizeHigh)) << 32); 00685 00686 if (lpFindFileData->dwFileAttributes 00687 & FILE_ATTRIBUTE_REPARSE_POINT) { 00688 /* TODO: test Windows symlinks */ 00689 /* TODO: MySQL has apparently its own symlink implementation in Windows, 00690 dbname.sym can redirect a database directory: 00691 http://www.mysql.com/doc/en/Windows_symbolic_links.html */ 00692 info->type = OS_FILE_TYPE_LINK; 00693 } else if (lpFindFileData->dwFileAttributes 00694 & FILE_ATTRIBUTE_DIRECTORY) { 00695 info->type = OS_FILE_TYPE_DIR; 00696 } else { 00697 /* It is probably safest to assume that all other 00698 file types are normal. Better to check them rather 00699 than blindly skip them. */ 00700 00701 info->type = OS_FILE_TYPE_FILE; 00702 } 00703 } 00704 00705 ut_free(lpFindFileData); 00706 00707 if (ret) { 00708 return(0); 00709 } else if (GetLastError() == ERROR_NO_MORE_FILES) { 00710 00711 return(1); 00712 } else { 00713 os_file_handle_error_no_exit(dirname, 00714 "readdir_next_file"); 00715 return(-1); 00716 } 00717 #else 00718 struct dirent* ent; 00719 char* full_path; 00720 int ret; 00721 struct stat statinfo; 00722 #ifdef HAVE_READDIR_R 00723 char dirent_buf[sizeof(struct dirent) + _POSIX_PATH_MAX + 00724 100]; 00725 /* In /mysys/my_lib.c, _POSIX_PATH_MAX + 1 is used as 00726 the max file name len; but in most standards, the 00727 length is NAME_MAX; we add 100 to be even safer */ 00728 #endif 00729 00730 next_file: 00731 00732 #ifdef HAVE_READDIR_R 00733 ret = readdir_r(dir, (struct dirent*)dirent_buf, &ent); 00734 00735 if (ret != 0) { 00736 fprintf(stderr, 00737 "InnoDB: cannot read directory %s, error %lu\n", dirname, (ulong)ret); 00738 00739 return(-1); 00740 } 00741 00742 if (ent == NULL) { 00743 /* End of directory */ 00744 00745 return(1); 00746 } 00747 00748 ut_a(strlen(ent->d_name) < _POSIX_PATH_MAX + 100 - 1); 00749 #else 00750 ent = readdir(dir); 00751 00752 if (ent == NULL) { 00753 00754 return(1); 00755 } 00756 #endif 00757 ut_a(strlen(ent->d_name) < OS_FILE_MAX_PATH); 00758 00759 if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) { 00760 00761 goto next_file; 00762 } 00763 00764 strcpy(info->name, ent->d_name); 00765 00766 full_path = ut_malloc(strlen(dirname) + strlen(ent->d_name) + 10); 00767 00768 sprintf(full_path, "%s/%s", dirname, ent->d_name); 00769 00770 ret = stat(full_path, &statinfo); 00771 00772 if (ret) { 00773 os_file_handle_error_no_exit(full_path, "stat"); 00774 00775 ut_free(full_path); 00776 00777 return(-1); 00778 } 00779 00780 info->size = (ib_longlong)statinfo.st_size; 00781 00782 if (S_ISDIR(statinfo.st_mode)) { 00783 info->type = OS_FILE_TYPE_DIR; 00784 } else if (S_ISLNK(statinfo.st_mode)) { 00785 info->type = OS_FILE_TYPE_LINK; 00786 } else if (S_ISREG(statinfo.st_mode)) { 00787 info->type = OS_FILE_TYPE_FILE; 00788 } else { 00789 info->type = OS_FILE_TYPE_UNKNOWN; 00790 } 00791 00792 ut_free(full_path); 00793 00794 return(0); 00795 #endif 00796 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_file_rename | ( | const char * | oldpath, | |
| const char * | newpath | |||
| ) |
Definition at line 1460 of file os0file.c.
References FALSE, os_file_handle_error(), and TRUE.
Referenced by fil_load_single_table_tablespace(), and fil_rename_tablespace().
01462 : TRUE if success */ 01463 const char* oldpath,/* in: old file path as a null-terminated 01464 string */ 01465 const char* newpath)/* in: new file path */ 01466 { 01467 #ifdef __WIN__ 01468 BOOL ret; 01469 01470 ret = MoveFile((LPCTSTR)oldpath, (LPCTSTR)newpath); 01471 01472 if (ret) { 01473 return(TRUE); 01474 } 01475 01476 os_file_handle_error(oldpath, "rename"); 01477 01478 return(FALSE); 01479 #else 01480 int ret; 01481 01482 ret = rename((const char*)oldpath, (const char*)newpath); 01483 01484 if (ret != 0) { 01485 os_file_handle_error(oldpath, "rename"); 01486 01487 return(FALSE); 01488 } 01489 01490 return(TRUE); 01491 #endif 01492 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_file_set_eof | ( | FILE * | file | ) |
Definition at line 1732 of file os0file.c.
References ftruncate, h, and HANDLE.
Referenced by row_ins_set_detailed(), and srv_lock_timeout_and_monitor_thread().
01734 : TRUE if success */ 01735 FILE* file) /* in: file to be truncated */ 01736 { 01737 #ifdef __WIN__ 01738 HANDLE h = (HANDLE) _get_osfhandle(fileno(file)); 01739 return(SetEndOfFile(h)); 01740 #else /* __WIN__ */ 01741 return(!ftruncate(fileno(file), ftell(file))); 01742 #endif /* __WIN__ */ 01743 }
Here is the caller graph for this function:

Definition at line 1643 of file os0file.c.
References buf, FALSE, memset, os_file_flush(), os_file_write(), TRUE, UNIV_PAGE_SIZE, ut_a, ut_align(), ut_free(), ut_malloc(), and ut_min().
Referenced by fil_create_new_single_table_tablespace(), open_or_create_data_files(), and open_or_create_log_file().
01645 : TRUE if success */ 01646 const char* name, /* in: name of the file or path as a 01647 null-terminated string */ 01648 os_file_t file, /* in: handle to a file */ 01649 ulint size, /* in: least significant 32 bits of file 01650 size */ 01651 ulint size_high)/* in: most significant 32 bits of size */ 01652 { 01653 ib_longlong current_size; 01654 ib_longlong desired_size; 01655 ibool ret; 01656 byte* buf; 01657 byte* buf2; 01658 ulint buf_size; 01659 01660 ut_a(size == (size & 0xFFFFFFFF)); 01661 01662 current_size = 0; 01663 desired_size = (ib_longlong)size + (((ib_longlong)size_high) << 32); 01664 01665 /* Write up to 1 megabyte at a time. */ 01666 buf_size = ut_min(64, (ulint) (desired_size / UNIV_PAGE_SIZE)) 01667 * UNIV_PAGE_SIZE; 01668 buf2 = ut_malloc(buf_size + UNIV_PAGE_SIZE); 01669 01670 /* Align the buffer for possible raw i/o */ 01671 buf = ut_align(buf2, UNIV_PAGE_SIZE); 01672 01673 /* Write buffer full of zeros */ 01674 memset(buf, 0, buf_size); 01675 01676 if (desired_size >= (ib_longlong)(100 * 1024 * 1024)) { 01677 01678 fprintf(stderr, "InnoDB: Progress in MB:"); 01679 } 01680 01681 while (current_size < desired_size) { 01682 ulint n_bytes; 01683 01684 if (desired_size - current_size < (ib_longlong) buf_size) { 01685 n_bytes = (ulint) (desired_size - current_size); 01686 } else { 01687 n_bytes = buf_size; 01688 } 01689 01690 ret = os_file_write(name, file, buf, 01691 (ulint)(current_size & 0xFFFFFFFF), 01692 (ulint)(current_size >> 32), 01693 n_bytes); 01694 if (!ret) { 01695 ut_free(buf2); 01696 goto error_handling; 01697 } 01698 01699 /* Print about progress for each 100 MB written */ 01700 if ((current_size + n_bytes) / (ib_longlong)(100 * 1024 * 1024) 01701 != current_size / (ib_longlong)(100 * 1024 * 1024)) { 01702 01703 fprintf(stderr, " %lu00", 01704 (ulong) ((current_size + n_bytes) 01705 / (ib_longlong)(100 * 1024 * 1024))); 01706 } 01707 01708 current_size += n_bytes; 01709 } 01710 01711 if (desired_size >= (ib_longlong)(100 * 1024 * 1024)) { 01712 01713 fprintf(stderr, "\n"); 01714 } 01715 01716 ut_free(buf2); 01717 01718 ret = os_file_flush(file); 01719 01720 if (ret) { 01721 return(TRUE); 01722 } 01723 01724 error_handling: 01725 return(FALSE); 01726 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_file_status | ( | const char * | path, | |
| ibool * | exists, | |||
| os_file_type_t * | type | |||
| ) |
Definition at line 2460 of file os0file.c.
References errno, FALSE, os_file_handle_error_no_exit(), OS_FILE_TYPE_DIR, OS_FILE_TYPE_FILE, OS_FILE_TYPE_LINK, OS_FILE_TYPE_UNKNOWN, S_ISDIR, S_ISLNK, and TRUE.
Referenced by os_file_create_subdirs_if_needed().
02462 : TRUE if call succeeded */ 02463 const char* path, /* in: pathname of the file */ 02464 ibool* exists, /* out: TRUE if file exists */ 02465 os_file_type_t* type) /* out: type of the file (if it exists) */ 02466 { 02467 #ifdef __WIN__ 02468 int ret; 02469 struct _stat statinfo; 02470 02471 ret = _stat(path, &statinfo); 02472 if (ret && (errno == ENOENT || errno == ENOTDIR)) { 02473 /* file does not exist */ 02474 *exists = FALSE; 02475 return(TRUE); 02476 } else if (ret) { 02477 /* file exists, but stat call failed */ 02478 02479 os_file_handle_error_no_exit(path, "stat"); 02480 02481 return(FALSE); 02482 } 02483 02484 if (_S_IFDIR & statinfo.st_mode) { 02485 *type = OS_FILE_TYPE_DIR; 02486 } else if (_S_IFREG & statinfo.st_mode) { 02487 *type = OS_FILE_TYPE_FILE; 02488 } else { 02489 *type = OS_FILE_TYPE_UNKNOWN; 02490 } 02491 02492 *exists = TRUE; 02493 02494 return(TRUE); 02495 #else 02496 int ret; 02497 struct stat statinfo; 02498 02499 ret = stat(path, &statinfo); 02500 if (ret && (errno == ENOENT || errno == ENOTDIR)) { 02501 /* file does not exist */ 02502 *exists = FALSE; 02503 return(TRUE); 02504 } else if (ret) { 02505 /* file exists, but stat call failed */ 02506 02507 os_file_handle_error_no_exit(path, "stat"); 02508 02509 return(FALSE); 02510 } 02511 02512 if (S_ISDIR(statinfo.st_mode)) { 02513 *type = OS_FILE_TYPE_DIR; 02514 } else if (S_ISLNK(statinfo.st_mode)) { 02515 *type = OS_FILE_TYPE_LINK; 02516 } else if (S_ISREG(statinfo.st_mode)) { 02517 *type = OS_FILE_TYPE_FILE; 02518 } else { 02519 *type = OS_FILE_TYPE_UNKNOWN; 02520 } 02521 02522 *exists = TRUE; 02523 02524 return(TRUE); 02525 #endif 02526 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_file_write | ( | const char * | name, | |
| os_file_t | file, | |||
| const void * | buf, | |||
| ulint | offset, | |||
| ulint | offset_high, | |||
| ulint | n | |||
| ) |
Definition at line 2285 of file os0file.c.
References err, errno, FALSE, TaoCrypt::NO_ERROR, NULL, os_file_count_mutex, os_file_flush(), OS_FILE_N_SEEK_MUTEXES, os_file_pwrite(), os_file_seek_mutexes, os_has_said_disk_full, os_mutex_enter(), os_mutex_exit(), os_n_file_writes, os_n_pending_writes, os_thread_sleep(), TRUE, ut_a, ut_ad, and ut_print_timestamp().
Referenced by fil_create_new_single_table_tablespace(), fil_extend_space_to_desired_size(), fil_reset_too_high_lsns(), os_aio(), and os_file_set_size().
02287 : TRUE if request was 02288 successful, FALSE if fail */ 02289 const char* name, /* in: name of the file or path as a 02290 null-terminated string */ 02291 os_file_t file, /* in: handle to a file */ 02292 const void* buf, /* in: buffer from which to write */ 02293 ulint offset, /* in: least significant 32 bits of file 02294 offset where to write */ 02295 ulint offset_high, /* in: most significant 32 bits of 02296 offset */ 02297 ulint n) /* in: number of bytes to write */ 02298 { 02299 #ifdef __WIN__ 02300 BOOL ret; 02301 DWORD len; 02302 DWORD ret2; 02303 DWORD low; 02304 DWORD high; 02305 ulint i; 02306 ulint n_retries = 0; 02307 ulint err; 02308 02309 ut_a((offset & 0xFFFFFFFF) == offset); 02310 02311 os_n_file_writes++; 02312 02313 ut_ad(file); 02314 ut_ad(buf); 02315 ut_ad(n > 0); 02316 retry: 02317 low = (DWORD) offset; 02318 high = (DWORD) offset_high; 02319 02320 os_mutex_enter(os_file_count_mutex); 02321 os_n_pending_writes++; 02322 os_mutex_exit(os_file_count_mutex); 02323 02324 /* Protect the seek / write operation with a mutex */ 02325 i = ((ulint) file) % OS_FILE_N_SEEK_MUTEXES; 02326 02327 os_mutex_enter(os_file_seek_mutexes[i]); 02328 02329 ret2 = SetFilePointer(file, low, &high, FILE_BEGIN); 02330 02331 if (ret2 == 0xFFFFFFFF && GetLastError() != NO_ERROR) { 02332 02333 os_mutex_exit(os_file_seek_mutexes[i]); 02334 02335 os_mutex_enter(os_file_count_mutex); 02336 os_n_pending_writes--; 02337 os_mutex_exit(os_file_count_mutex); 02338 02339 ut_print_timestamp(stderr); 02340 02341 fprintf(stderr, 02342 " InnoDB: Error: File pointer positioning to file %s failed at\n" 02343 "InnoDB: offset %lu %lu. Operating system error number %lu.\n" 02344 "InnoDB: Some operating system error numbers are described at\n" 02345 "InnoDB: " 02346 "http://dev.mysql.com/doc/mysql/en/Operating_System_error_codes.html\n", 02347 name, (ulong) offset_high, (ulong) offset, 02348 (ulong) GetLastError()); 02349 02350 return(FALSE); 02351 } 02352 02353 ret = WriteFile(file, buf, (DWORD) n, &len, NULL); 02354 02355 /* Always do fsync to reduce the probability that when the OS crashes, 02356 a database page is only partially physically written to disk. */ 02357 02358 # ifdef UNIV_DO_FLUSH 02359 if (!os_do_not_call_flush_at_each_write) { 02360 ut_a(TRUE == os_file_flush(file)); 02361 } 02362 # endif /* UNIV_DO_FLUSH */ 02363 02364 os_mutex_exit(os_file_seek_mutexes[i]); 02365 02366 os_mutex_enter(os_file_count_mutex); 02367 os_n_pending_writes--; 02368 os_mutex_exit(os_file_count_mutex); 02369 02370 if (ret && len == n) { 02371 02372 return(TRUE); 02373 } 02374 02375 /* If some background file system backup tool is running, then, at 02376 least in Windows 2000, we may get here a specific error. Let us 02377 retry the operation 100 times, with 1 second waits. */ 02378 02379 if (GetLastError() == ERROR_LOCK_VIOLATION && n_retries < 100) { 02380 02381 os_thread_sleep(1000000); 02382 02383 n_retries++; 02384 02385 goto retry; 02386 } 02387 02388 if (!os_has_said_disk_full) { 02389 02390 err = (ulint)GetLastError(); 02391 02392 ut_print_timestamp(stderr); 02393 02394 fprintf(stderr, 02395 " InnoDB: Error: Write to file %s failed at offset %lu %lu.\n" 02396 "InnoDB: %lu bytes should have been written, only %lu were written.\n" 02397 "InnoDB: Operating system error number %lu.\n" 02398 "InnoDB: Check that your OS and file system support files of this size.\n" 02399 "InnoDB: Check also that the disk is not full or a disk quota exceeded.\n", 02400 name, (ulong) offset_high, (ulong) offset, 02401 (ulong) n, (ulong) len, (ulong) err); 02402 02403 if (strerror((int)err) != NULL) { 02404 fprintf(stderr, 02405 "InnoDB: Error number %lu means '%s'.\n", (ulong) err, strerror((int)err)); 02406 } 02407 02408 fprintf(stderr, 02409 "InnoDB: Some operating system error numbers are described at\n" 02410 "InnoDB: " 02411 "http://dev.mysql.com/doc/mysql/en/Operating_System_error_codes.html\n"); 02412 02413 os_has_said_disk_full = TRUE; 02414 } 02415 02416 return(FALSE); 02417 #else 02418 ssize_t ret; 02419 02420 ret = os_file_pwrite(file, buf, n, offset, offset_high); 02421 02422 if ((ulint)ret == n) { 02423 02424 return(TRUE); 02425 } 02426 02427 if (!os_has_said_disk_full) { 02428 02429 ut_print_timestamp(stderr); 02430 02431 fprintf(stderr, 02432 " InnoDB: Error: Write to file %s failed at offset %lu %lu.\n" 02433 "InnoDB: %lu bytes should have been written, only %ld were written.\n" 02434 "InnoDB: Operating system error number %lu.\n" 02435 "InnoDB: Check that your OS and file system support files of this size.\n" 02436 "InnoDB: Check also that the disk is not full or a disk quota exceeded.\n", 02437 name, offset_high, offset, n, (long int)ret, 02438 (ulint)errno); 02439 if (strerror(errno) != NULL) { 02440 fprintf(stderr, 02441 "InnoDB: Error number %lu means '%s'.\n", (ulint)errno, strerror(errno)); 02442 } 02443 02444 fprintf(stderr, 02445 "InnoDB: Some operating system error numbers are described at\n" 02446 "InnoDB: " 02447 "http://dev.mysql.com/doc/mysql/en/Operating_System_error_codes.html\n"); 02448 02449 os_has_said_disk_full = TRUE; 02450 } 02451 02452 return(FALSE); 02453 #endif 02454 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ulint os_get_os_version | ( | void | ) |
Definition at line 174 of file os0file.c.
References OS_WIN2000, OS_WIN31, OS_WIN95, OS_WINNT, ut_a, and ut_error.
Referenced by innobase_start_or_create_for_mysql().
00176 : OS_WIN95, OS_WIN31, OS_WINNT, OS_WIN2000 */ 00177 { 00178 #ifdef __WIN__ 00179 OSVERSIONINFO os_info; 00180 00181 os_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 00182 00183 ut_a(GetVersionEx(&os_info)); 00184 00185 if (os_info.dwPlatformId == VER_PLATFORM_WIN32s) { 00186 return(OS_WIN31); 00187 } else if (os_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { 00188 return(OS_WIN95); 00189 } else if (os_info.dwPlatformId == VER_PLATFORM_WIN32_NT) { 00190 if (os_info.dwMajorVersion <= 4) { 00191 return(OS_WINNT); 00192 } else { 00193 return(OS_WIN2000); 00194 } 00195 } else { 00196 ut_error; 00197 return(0); 00198 } 00199 #else 00200 ut_error; 00201 00202 return(0); 00203 #endif 00204 }
Here is the caller graph for this function:

| void os_io_init_simple | ( | void | ) |
Definition at line 491 of file os0file.c.
References NULL, os_file_count_mutex, OS_FILE_N_SEEK_MUTEXES, os_file_seek_mutexes, and os_mutex_create().
Referenced by os_aio_init().
00493 { 00494 ulint i; 00495 00496 os_file_count_mutex = os_mutex_create(NULL); 00497 00498 for (i = 0; i < OS_FILE_N_SEEK_MUTEXES; i++) { 00499 os_file_seek_mutexes[i] = os_mutex_create(NULL); 00500 } 00501 }
Here is the call graph for this function:

Here is the caller graph for this function:

| ibool os_aio_print_debug |
Definition at line 65 of file os0file.c.
Referenced by buf_read_recv_pages(), and os_aio_simulated_handle().
| ibool os_aio_use_native_aio |
Definition at line 63 of file os0file.c.
Referenced by fil_aio_wait(), innobase_start_or_create_for_mysql(), os_aio(), os_aio_array_reserve_slot(), os_aio_simulated_wake_handler_thread(), os_aio_simulated_wake_handler_threads(), and os_file_create().
| ibool os_has_said_disk_full |
Definition at line 161 of file os0file.c.
Referenced by fil_extend_space_to_desired_size(), os_file_handle_error(), os_file_handle_error_no_exit(), and os_file_write().
Definition at line 152 of file os0file.c.
Referenced by buf_LRU_get_free_block(), os_aio(), os_file_pread(), os_file_read(), os_file_read_no_error_handling(), and srv_export_innodb_status().
Definition at line 154 of file os0file.c.
Referenced by buf_LRU_get_free_block(), os_aio(), os_file_pwrite(), os_file_write(), and srv_export_innodb_status().
Definition at line 155 of file os0file.c.
Referenced by buf_LRU_get_free_block(), os_aio_refresh_stats(), os_file_flush(), and srv_export_innodb_status().
Definition at line 168 of file os0file.c.
Referenced by os_file_pread(), os_file_read(), os_file_read_no_error_handling(), and srv_export_innodb_status().
Definition at line 167 of file os0file.c.
Referenced by os_file_pwrite(), os_file_write(), and srv_export_innodb_status().
1.4.7

