Skip to content

Commit a1b6128

Browse files
committed
MDEV-11264 Fix DeviceIoControl() usage in innodb.
As documented in MSDN, DeviceIoControl() needs valid (not NULL) OVERLAPPED parameter, for files opened with for OVERLAPPED access.
1 parent b61700c commit a1b6128

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

storage/xtradb/os/os0file.cc

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6423,22 +6423,27 @@ os_file_trim(
64236423
flt.Ranges[0].Offset = off;
64246424
flt.Ranges[0].Length = trim_len;
64256425

6426+
OVERLAPPED overlapped = { 0 };
6427+
overlapped.hEvent = win_get_syncio_event();
64266428
BOOL ret = DeviceIoControl(slot->file, FSCTL_FILE_LEVEL_TRIM,
6427-
&flt, sizeof(flt), NULL, NULL, NULL, NULL);
6428-
6429+
&flt, sizeof(flt), NULL, NULL, NULL, &overlapped);
6430+
DWORD tmp;
6431+
if (ret) {
6432+
ret = GetOverlappedResult(slot->file, &overlapped, &tmp, FALSE);
6433+
}
6434+
else if (GetLastError() == ERROR_IO_PENDING) {
6435+
ret = GetOverlappedResult(slot->file, &overlapped, &tmp, TRUE);
6436+
}
64296437
if (!ret) {
6438+
DWORD last_error = GetLastError();
64306439
/* After first failure do not try to trim again */
64316440
os_fallocate_failed = true;
64326441
srv_use_trim = FALSE;
64336442
ut_print_timestamp(stderr);
6434-
fprintf(stderr,
6435-
" InnoDB: Warning: fallocate call failed with error.\n"
6436-
" InnoDB: start: %lu len: %lu payload: %lu\n"
6437-
" InnoDB: Disabling fallocate for now.\n", off, trim_len, len);
64386443

6439-
os_file_handle_error_no_exit(slot->name,
6440-
" DeviceIOControl(FSCTL_FILE_LEVEL_TRIM) ",
6441-
FALSE, __FILE__, __LINE__);
6444+
fprintf(stderr,
6445+
" InnoDB: Warning: DeviceIoControl(FSCTL_FILE_LEVEL_TRIM) call failed with error %u%s. Disabling trimming.\n",
6446+
last_error, last_error == ERROR_NOT_SUPPORTED ? "(ERROR_NOT_SUPPORTED)" : "");
64426447

64436448
if (slot->write_size) {
64446449
*slot->write_size = 0;

0 commit comments

Comments
 (0)