Skip to content

MDEV-39925: Fix error reporting in create_libaio#5192

Open
andreas-schwab wants to merge 1 commit into
MariaDB:mainfrom
andreas-schwab:main
Open

MDEV-39925: Fix error reporting in create_libaio#5192
andreas-schwab wants to merge 1 commit into
MariaDB:mainfrom
andreas-schwab:main

Conversation

@andreas-schwab

Copy link
Copy Markdown

The io_setup function in libaio returns a negated errno value on error,
but strerror expects a normal errno value.

The io_setup function in libaio returns a negated errno value on error,
but strerror expects a normal errno value.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies tpool/aio_libaio.cc to pass the negated return value of io_setup to strerror when printing a warning message. Since io_setup returns a negative error code on failure, negating it ensures strerror receives the correct positive error number. There are no review comments, and I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread tpool/aio_libaio.cc
Comment on lines 202 to 207
if (int ret= io_setup(max_io, &ctx))
{
fprintf(stderr, "Warning: io_setup(%d) returned %s. See man 2 io_setup.\n",
max_io, strerror(ret));
max_io, strerror(-ret));
return nullptr;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man 2 io_setup on my Debian GNU/Linux Sid system tells me that we’d better check the errno:

RETURN VALUE

On success, io_setup() returns 0. On error, -1 is returned, and errno is set to indicate the error.

Did you test the following?

  if (io_setup(max_io, &ctx))
  {
    fprintf(stderr, "Warning: io_setup(%d) returned %s. See man 2 io_setup.\n",
            max_io, strerror(errno));

@vaintroub vaintroub Jun 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously , only numeric errno was printed out, which at least would not sparkle this discussion. I think numeric value should still be printed maybe together with strerror. At least we'd know if @andreas-schwab is right. Also, not everyone in support like to read a possibly localized error. @grooverdan ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dr-m as already said: man 2 io_setup notes there's a syscall difference with the libaio wrappers that we use related to this particular case of error handling. The suggested variant is rather worse:

Warning: io_setup(2048) returned Success. See man 2 io_setup.
2026-06-09 12:17:32 0 [Warning] InnoDB: native AIO failed: falling back to innodb_use_native_aio=OFF

@andreas-schwab is right and I tested:

Warning: io_setup(2048) returned Resource temporarily unavailable. See man 2 io_setup.

I think numeric value should still be printed maybe together with strerror.

Easy enough.

diff --git a/tpool/aio_libaio.cc b/tpool/aio_libaio.cc
index 013c407c205..1ca82a080a1 100644
--- a/tpool/aio_libaio.cc
+++ b/tpool/aio_libaio.cc
@@ -201,8 +201,8 @@ aio *create_libaio(thread_pool *pool, int max_io)
   memset(&ctx, 0, sizeof ctx);
   if (int ret= io_setup(max_io, &ctx))
   {
-    fprintf(stderr, "Warning: io_setup(%d) returned %s. See man 2 io_setup.\n",
-            max_io, strerror(-ret));
+    fprintf(stderr, "Warning: io_setup(%d) returned %s(errno: %d). See man 2 io_setup.\n",
+            max_io, strerror(-ret), -ret);
     return nullptr;
   }
   return new aio_libaio(ctx, pool);

To output:

Warning: io_setup(2048) returned Resource temporarily unavailable(errno: 11). See man 2 io_setup.

Leaving support folks to double check with:

$ errno 11
EAGAIN 11 Resource temporarily unavailable

Which matches the err on the man page.

Thanks @andreas-schwab. If you could:

  • rebase to 10.11, git force push (to same branch name, and edit PR title to adjust target branch to 10.11)
  • include MDEV at beginning of commit
  • include numeric output
  • a quick "I submit this under the MCA" or "I submit this under a BSD-new" PR comment.

Thanks for fixing my incorrect code in ba9e8eb.

@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Jun 8, 2026
@gkodinov gkodinov changed the title Fix error reporting in create_libaio MDEV-39925: Fix error reporting in create_libaio Jun 8, 2026

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! This is a preliminary review.

  • Please backport the fix to 10.11: this is a bug fix and 10.11 suffers the same issues.
  • For future reference pease consider filing a jira with the description of the problem first. I did open one for you on this.
  • Please sort out the CLA assistant in the pull request test section. You will need to clearly indicate the licensing on your fix.

Otherwise, the fix itself is reasonable and I see that you are already working with Marko on it. Good stuff! Please keep doing that.

@andreas-schwab

Copy link
Copy Markdown
Author

Please read the whole manpage:

   Note that the libaio wrapper function uses a  different  type  (io_con-
   text_t *)  for the ctx_idp argument.  Note also that the libaio wrapper
   does not follow the usual C library conventions for indicating  errors:
   on  error it returns a negated error number (the negative of one of the
   values  listed  in  ERRORS).   If  the  system  call  is  invoked   via
   syscall(2), then the return value follows the usual conventions for in-
   dicating an error: -1, with errno set to a (positive) value that  indi-
   cates the error.

@andreas-schwab

Copy link
Copy Markdown
Author

@gkodinov

gkodinov commented Jun 8, 2026

Copy link
Copy Markdown
Member

https://cla-assistant.io/MariaDB/server?pullRequest=5192 doesn't work.

then just put a comment about the licensing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

6 participants