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