36
ulint os_innodb_umask = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
36
UNIV_INTERN ulint os_innodb_umask
37
= S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
38
ulint os_innodb_umask = 0;
39
UNIV_INTERN ulint os_innodb_umask = 0;
41
42
#ifdef UNIV_DO_FLUSH
42
43
/* If the following is set to TRUE, we do not call os_file_flush in every
43
44
os_file_write. We can set this TRUE when the doublewrite buffer is used. */
44
ibool os_do_not_call_flush_at_each_write = FALSE;
45
UNIV_INTERN ibool os_do_not_call_flush_at_each_write = FALSE;
46
47
/* We do not call os_file_flush in every os_file_write. */
47
48
#endif /* UNIV_DO_FLUSH */
49
50
/* We use these mutexes to protect lseek + file i/o operation, if the
50
51
OS does not provide an atomic pread or pwrite, or similar */
51
52
#define OS_FILE_N_SEEK_MUTEXES 16
52
os_mutex_t os_file_seek_mutexes[OS_FILE_N_SEEK_MUTEXES];
53
UNIV_INTERN os_mutex_t os_file_seek_mutexes[OS_FILE_N_SEEK_MUTEXES];
54
55
/* In simulated aio, merge at most this many consecutive i/os */
55
56
#define OS_AIO_MERGE_N_CONSECUTIVE 64
58
59
OS (provided we compiled Innobase with it in), otherwise we will
59
60
use simulated aio we build below with threads */
61
ibool os_aio_use_native_aio = FALSE;
62
UNIV_INTERN ibool os_aio_use_native_aio = FALSE;
63
ibool os_aio_print_debug = FALSE;
64
UNIV_INTERN ibool os_aio_print_debug = FALSE;
65
66
/* The aio array slot structure */
66
67
typedef struct os_aio_slot_struct os_aio_slot_t;
133
134
/* Array of events used in simulated aio */
134
os_event_t* os_aio_segment_wait_events = NULL;
135
static os_event_t* os_aio_segment_wait_events = NULL;
136
137
/* The aio arrays for non-ibuf i/o and ibuf i/o, as well as sync aio. These
137
138
are NULL when the module has not yet been initialized. */
147
148
wait until a batch of new read requests have been posted */
148
149
static ibool os_aio_recommend_sleep_for_read_threads = FALSE;
150
ulint os_n_file_reads = 0;
151
ulint os_bytes_read_since_printout = 0;
152
ulint os_n_file_writes = 0;
153
ulint os_n_fsyncs = 0;
154
ulint os_n_file_reads_old = 0;
155
ulint os_n_file_writes_old = 0;
156
ulint os_n_fsyncs_old = 0;
157
time_t os_last_printout;
151
UNIV_INTERN ulint os_n_file_reads = 0;
152
UNIV_INTERN ulint os_bytes_read_since_printout = 0;
153
UNIV_INTERN ulint os_n_file_writes = 0;
154
UNIV_INTERN ulint os_n_fsyncs = 0;
155
UNIV_INTERN ulint os_n_file_reads_old = 0;
156
UNIV_INTERN ulint os_n_file_writes_old = 0;
157
UNIV_INTERN ulint os_n_fsyncs_old = 0;
158
UNIV_INTERN time_t os_last_printout;
159
ibool os_has_said_disk_full = FALSE;
160
UNIV_INTERN ibool os_has_said_disk_full = FALSE;
161
162
/* The mutex protecting the following counts of pending I/O operations */
162
static os_mutex_t os_file_count_mutex;
163
ulint os_file_n_pending_preads = 0;
164
ulint os_file_n_pending_pwrites = 0;
165
ulint os_n_pending_writes = 0;
166
ulint os_n_pending_reads = 0;
163
static os_mutex_t os_file_count_mutex;
164
UNIV_INTERN ulint os_file_n_pending_preads = 0;
165
UNIV_INTERN ulint os_file_n_pending_pwrites = 0;
166
UNIV_INTERN ulint os_n_pending_writes = 0;
167
UNIV_INTERN ulint os_n_pending_reads = 0;
168
169
/***************************************************************************
169
170
Gets the operating system version. Currently works only on Windows. */
172
173
os_get_os_version(void)
173
174
/*===================*/
455
455
#undef USE_FILE_LOCK
456
456
#define USE_FILE_LOCK
457
#if defined(UNIV_HOTBACKUP) || defined(__WIN__)
457
#if defined(UNIV_HOTBACKUP) || defined(__WIN__) || defined(__NETWARE__)
458
458
/* InnoDB Hot Backup does not lock the data files.
459
459
* On Windows, mandatory locking is used.
513
#if !defined(UNIV_HOTBACKUP)
514
/*************************************************************************
515
Creates a temporary file that will be deleted on close.
516
This function is defined in ha_innodb.cc. */
519
innobase_mysql_tmpfile(void);
520
/*========================*/
521
/* out: temporary file descriptor, or < 0 on error */
522
#endif /* !UNIV_HOTBACKUP */
524
513
/***************************************************************************
525
514
Creates a temporary file. This function is like tmpfile(3), but
526
515
the temporary file is created in the MySQL temporary directory.
527
516
On Netware, this function is like tmpfile(3), because the C run-time
528
517
library of Netware does not expose the delete-on-close flag. */
531
520
os_file_create_tmpfile(void)
532
521
/*========================*/
530
FILE* file = tmpfile();
531
# else /* __NETWARE__ */
540
532
FILE* file = NULL;
541
533
int fd = innobase_mysql_tmpfile();
544
536
file = fdopen(fd, "w+b");
538
# endif /* __NETWARE__ */
548
541
ut_print_timestamp(stderr);
550
543
" InnoDB: Error: unable to create temporary file;"
551
544
" errno: %d\n", errno);
549
# endif /* !__NETWARE__ */
655
650
/***************************************************************************
656
651
This function returns information of the next file in the directory. We jump
657
652
over the '.' and '..' entries in the directory. */
660
655
os_file_readdir_next_file(
661
656
/*======================*/
686
681
strcpy(info->name, (char *) lpFindFileData->cFileName);
688
info->size = (ib_longlong)(lpFindFileData->nFileSizeLow)
689
+ (((ib_longlong)(lpFindFileData->nFileSizeHigh))
683
info->size = (ib_int64_t)(lpFindFileData->nFileSizeLow)
684
+ (((ib_int64_t)(lpFindFileData->nFileSizeHigh))
692
687
if (lpFindFileData->dwFileAttributes
809
804
gets default permissions. On Unix the permissions are (0770 & ~umask). If the
810
805
directory exists already, nothing is done and the call succeeds, unless the
811
806
fail_if_exists arguments is true. */
814
809
os_file_create_directory(
815
810
/*=====================*/
1108
1103
/********************************************************************
1109
1104
Tries to disable OS caching on an opened file descriptor. */
1112
1107
os_file_set_nocache(
1113
1108
/*================*/
1114
int fd,/* in: file descriptor to alter */
1115
const char* file_name,/* in: used in the diagnostic
1117
const char* operation_name)/* in: used in the
1119
we call os_file_set_nocache()
1120
immediately after opening or creating
1121
a file, so this is either "open" or
1109
int fd, /* in: file descriptor to alter */
1110
const char* file_name, /* in: file name, used in the
1111
diagnostic message */
1112
const char* operation_name) /* in: "open" or "create"; used in the
1113
diagnostic message */
1124
1115
/* some versions of Solaris may not have DIRECTIO_ON */
1125
1116
#if defined(UNIV_SOLARIS) && defined(DIRECTIO_ON)
1398
1389
/***************************************************************************
1399
1390
Deletes a file if it exists. The file has to be closed before calling this. */
1402
1393
os_file_delete_if_exists(
1403
1394
/*=====================*/
1550
ret = rename((const char*)oldpath, (const char*)newpath);
1541
ret = rename(oldpath, newpath);
1552
1543
if (ret != 0) {
1553
1544
os_file_handle_error_no_exit(oldpath, "rename");
1684
1675
/***************************************************************************
1685
Gets file size as a 64-bit integer ib_longlong. */
1676
Gets file size as a 64-bit integer ib_int64_t. */
1688
1679
os_file_get_size_as_iblonglong(
1689
1680
/*===========================*/
1690
1681
/* out: size in bytes, -1 if error */
1704
return((((ib_longlong)size_high) << 32) + (ib_longlong)size);
1695
return((((ib_int64_t)size_high) << 32) + (ib_int64_t)size);
1707
1698
/***************************************************************************
1708
1699
Write the specified number of zeros to a newly created file. */
1711
1702
os_file_set_size(
1712
1703
/*=============*/
1728
1719
ut_a(size == (size & 0xFFFFFFFF));
1730
1721
current_size = 0;
1731
desired_size = (ib_longlong)size + (((ib_longlong)size_high) << 32);
1722
desired_size = (ib_int64_t)size + (((ib_int64_t)size_high) << 32);
1733
1724
/* Write up to 1 megabyte at a time. */
1734
1725
buf_size = ut_min(64, (ulint) (desired_size / UNIV_PAGE_SIZE))
1741
1732
/* Write buffer full of zeros */
1742
1733
memset(buf, 0, buf_size);
1744
if (desired_size >= (ib_longlong)(100 * 1024 * 1024)) {
1735
if (desired_size >= (ib_int64_t)(100 * 1024 * 1024)) {
1746
1737
fprintf(stderr, "InnoDB: Progress in MB:");
1749
1740
while (current_size < desired_size) {
1752
if (desired_size - current_size < (ib_longlong) buf_size) {
1743
if (desired_size - current_size < (ib_int64_t) buf_size) {
1753
1744
n_bytes = (ulint) (desired_size - current_size);
1755
1746
n_bytes = buf_size;
1767
1758
/* Print about progress for each 100 MB written */
1768
if ((ib_longlong) (current_size + n_bytes) / (ib_longlong)(100 * 1024 * 1024)
1769
!= current_size / (ib_longlong)(100 * 1024 * 1024)) {
1759
if ((ib_int64_t) (current_size + n_bytes) / (ib_int64_t)(100 * 1024 * 1024)
1760
!= current_size / (ib_int64_t)(100 * 1024 * 1024)) {
1771
1762
fprintf(stderr, " %lu00",
1772
1763
(ulong) ((current_size + n_bytes)
1773
/ (ib_longlong)(100 * 1024 * 1024)));
1764
/ (ib_int64_t)(100 * 1024 * 1024)));
1776
1767
current_size += n_bytes;
1779
if (desired_size >= (ib_longlong)(100 * 1024 * 1024)) {
1770
if (desired_size >= (ib_int64_t)(100 * 1024 * 1024)) {
1781
1772
fprintf(stderr, "\n");
2276
2267
/***********************************************************************
2277
2268
Requests a synchronous positioned read operation. This function does not do
2278
2269
any error handling. In case of error it returns FALSE. */
2281
2272
os_file_read_no_error_handling(
2282
2273
/*===========================*/
3028
3019
/****************************************************************************
3029
3020
Wakes up all async i/o threads so that they know to exit themselves in
3033
3024
os_aio_wake_all_threads_at_shutdown(void)
3034
3025
/*=====================================*/
3053
3044
/****************************************************************************
3054
3045
Waits until there are no pending writes in os_aio_write_array. There can
3055
3046
be other, synchronous, pending writes. */
3058
3049
os_aio_wait_until_no_pending_writes(void)
3059
3050
/*=====================================*/
3390
3381
/**************************************************************************
3391
3382
Wakes up simulated aio i/o-handler threads if they have something to do. */
3394
3385
os_aio_simulated_wake_handler_threads(void)
3395
3386
/*=======================================*/
3414
3405
prefers an i/o-handler thread to handle them all at once later. You must
3415
3406
call os_aio_simulated_wake_handler_threads later to ensure the threads
3416
3407
are not left sleeping! */
3419
3410
os_aio_simulated_put_read_threads_to_sleep(void)
3420
3411
/*============================================*/
3823
3814
/**************************************************************************
3824
Do a 'last millisecond' check that the page end is sensible;
3825
reported page checksum errors from Linux seem to wipe over the page end. */
3828
os_file_check_page_trailers(
3829
/*========================*/
3830
byte* combined_buf, /* in: combined write buffer */
3831
ulint total_len) /* in: size of combined_buf, in bytes
3832
(a multiple of UNIV_PAGE_SIZE) */
3836
for (len = 0; len + UNIV_PAGE_SIZE <= total_len;
3837
len += UNIV_PAGE_SIZE) {
3838
byte* buf = combined_buf + len;
3841
(memcmp(buf + (FIL_PAGE_LSN + 4),
3842
buf + (UNIV_PAGE_SIZE
3843
- FIL_PAGE_END_LSN_OLD_CHKSUM + 4), 4))) {
3844
ut_print_timestamp(stderr);
3846
" InnoDB: ERROR: The page to be written"
3848
"InnoDB: Writing a block of %lu bytes,"
3849
" currently at offset %lu\n",
3850
(ulong)total_len, (ulong)len);
3851
buf_page_print(buf);
3853
"InnoDB: ERROR: The page to be written"
3854
" seems corrupt!\n");
3859
/**************************************************************************
3860
3815
Does simulated aio. This function should be called by an i/o-handler
3864
3819
os_aio_simulated_handle(
3865
3820
/*====================*/
4093
4048
/* Do the i/o with ordinary, synchronous i/o functions: */
4094
4049
if (slot->type == OS_FILE_WRITE) {
4095
if (array == os_aio_write_array) {
4096
if ((total_len % UNIV_PAGE_SIZE != 0)
4097
|| (slot->offset % UNIV_PAGE_SIZE != 0)) {
4099
"InnoDB: Error: trying a displaced"
4100
" write to %s %lu %lu, len %lu\n",
4101
slot->name, (ulong) slot->offset_high,
4102
(ulong) slot->offset,
4107
os_file_check_page_trailers(combined_buf, total_len);
4110
4050
ret = os_file_write(slot->name, slot->file, combined_buf,
4111
4051
slot->offset, slot->offset_high,
4114
if (array == os_aio_write_array) {
4115
os_file_check_page_trailers(combined_buf, total_len);
4118
4054
ret = os_file_read(slot->file, combined_buf,
4119
4055
slot->offset, slot->offset_high, total_len);
4405
4341
/**************************************************************************
4406
4342
Checks that all slots in the system have been freed, that is, there are
4407
4343
no pending io operations. */
4410
4346
os_aio_all_slots_free(void)
4411
4347
/*=======================*/