Skip to content

Commit

Permalink
MDEV-11264 Fix DeviceIoControl() usage in innodb.
Browse files Browse the repository at this point in the history
As documented in MSDN, DeviceIoControl() needs valid (not NULL) OVERLAPPED
parameter, for files  opened with for OVERLAPPED access.
  • Loading branch information
vaintroub committed May 23, 2017
1 parent b61700c commit a1b6128
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions storage/xtradb/os/os0file.cc
Expand Up @@ -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;
Expand Down

0 comments on commit a1b6128

Please sign in to comment.