Bug #93937 Contribution: Linux use O_TMPFILE for create_temp_file
Submitted: 15 Jan 2019 13:33 Modified: 12 Feb 2019 20:15
Reporter: OCA Admin (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Locking Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: CPU Architecture:Any

[15 Jan 2019 13:33] OCA Admin
Description:
This bug tracks a contribution by Daniel Black (Github user: grooverdan) as described in http://github.com/mysql/mysql-server/pull/244

How to repeat:
See description

Suggested fix:
See contribution code attached
[15 Jan 2019 13:33] OCA Admin
Contribution submitted via Github - Linux use O_TMPFILE for create_temp_file 
(*) Contribution by Daniel Black (Github grooverdan, mysql-server/pull/244#issuecomment-454273623): I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: git_patch_244680466.txt (text/plain), 1.96 KiB.

[15 Jan 2019 13:51] MySQL Verification Team
Thank you for the contribution.
[15 Jan 2019 23:19] Daniel Black
For clarity, the main purpose of this is to change create_file and then unlink to just a create_file.

In addition to saving a system call for the unlink, and the small race condition of an empty file, there's shorter path within the kernel filesystem code.
[8 Feb 2019 9:22] Tor Didriksen
Posted by developer:
 
Supported only on select platforms, e.g. not until RedHat 7.6

https://bugzilla.redhat.com/show_bug.cgi?id=1471405
[12 Feb 2019 20:15] Paul DuBois
Posted by developer:
 
Fixed in 8.0.17.

MySQL now uses open(O_TMPFILE) whenever applicable when creating a
temporary file that is immediately unlinked. This is more efficient
than previously and avoids the small possibility of a race condition.
Thanks to Daniel Black for the contribution.
[12 Feb 2019 22:52] Daniel Black
Thanks Tor and Paul for the merge.
[15 Feb 2019 8:44] Frederic Descamps
Thank you for your contribution, it has been processed by our development and documentation team.

Your contribution will be part of a future release.

Regards,
[3 May 2019 6:40] Daniel Black
patch for gcc-8

Attachment: p.p (text/x-pascal), 1.14 KiB.

[3 May 2019 6:46] Daniel Black
Thanks to a tipoff by Marko Mäkelä

The glibc open has its first argument defined as notnull. gcc-8+ optimize the implementation of this aggressively by assuming that constraint is strict. In the original patch provided I called with dirname = NULL in a couple of cases which can optimize away some later dirname==NULL checks.

The patch provided is on top of the original to generate correct code under gcc-8+ compilers by ensuring dirname is not NULL before it gets to the open glibc implementation.