Skip to content
Permalink
Browse files

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.
  • Loading branch information...
vaintroub committed May 22, 2017
1 parent b61700c commit a1b6128dedb4419db9fadaf94c356d3477d4e06f
Showing with 14 additions and 9 deletions.
  1. +14 −9 storage/xtradb/os/os0file.cc
@@ -6423,22 +6423,27 @@ os_file_trim(
flt.Ranges[0].Offset = off;
flt.Ranges[0].Length = trim_len;

OVERLAPPED overlapped = { 0 };
overlapped.hEvent = win_get_syncio_event();
BOOL ret = DeviceIoControl(slot->file, FSCTL_FILE_LEVEL_TRIM,
&flt, sizeof(flt), NULL, NULL, NULL, NULL);

&flt, sizeof(flt), NULL, NULL, NULL, &overlapped);
DWORD tmp;
if (ret) {
ret = GetOverlappedResult(slot->file, &overlapped, &tmp, FALSE);
}
else if (GetLastError() == ERROR_IO_PENDING) {
ret = GetOverlappedResult(slot->file, &overlapped, &tmp, TRUE);
}
if (!ret) {
DWORD last_error = GetLastError();
/* After first failure do not try to trim again */
os_fallocate_failed = true;
srv_use_trim = FALSE;
ut_print_timestamp(stderr);
fprintf(stderr,
" InnoDB: Warning: fallocate call failed with error.\n"
" InnoDB: start: %lu len: %lu payload: %lu\n"
" InnoDB: Disabling fallocate for now.\n", off, trim_len, len);

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

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

0 comments on commit a1b6128

Please sign in to comment.
You can’t perform that action at this time.