summaryrefslogtreecommitdiffstats
path: root/mysys/mf_tempfile.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 13:22:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 13:22:53 +0000
commit347c164c35eddab388009470e6848cb361ac93f8 (patch)
tree2c0c44eac690f510bb0a35b2a13b36d606b77b6b /mysys/mf_tempfile.c
parentReleasing progress-linux version 1:10.11.7-4~progress7.99u1. (diff)
downloadmariadb-347c164c35eddab388009470e6848cb361ac93f8.tar.xz
mariadb-347c164c35eddab388009470e6848cb361ac93f8.zip
Merging upstream version 1:10.11.8.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mysys/mf_tempfile.c')
-rw-r--r--mysys/mf_tempfile.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/mysys/mf_tempfile.c b/mysys/mf_tempfile.c
index 0f1c6d6b..3393b610 100644
--- a/mysys/mf_tempfile.c
+++ b/mysys/mf_tempfile.c
@@ -66,7 +66,11 @@ File create_temp_file(char *to, const char *dir, const char *prefix,
DBUG_ENTER("create_temp_file");
DBUG_PRINT("enter", ("dir: %s, prefix: %s", dir ? dir : "(null)", prefix));
+#if !defined _WIN32 && defined O_DIRECT
+ DBUG_ASSERT((mode & (O_EXCL | O_TRUNC | O_CREAT | O_RDWR | O_DIRECT)) == 0);
+#else
DBUG_ASSERT((mode & (O_EXCL | O_TRUNC | O_CREAT | O_RDWR)) == 0);
+#endif
mode|= O_TRUNC | O_CREAT | O_RDWR; /* not O_EXCL, see Windows code below */
@@ -118,16 +122,41 @@ File create_temp_file(char *to, const char *dir, const char *prefix,
if ((MyFlags & MY_TEMPORARY) && O_TMPFILE_works)
{
- /* explictly don't use O_EXCL here has it has a different
- meaning with O_TMPFILE
+ /*
+ explicitly don't use O_EXCL here has it has a different
+ meaning with O_TMPFILE
*/
- if ((file= open(dir, (mode & ~O_CREAT) | O_TMPFILE | O_CLOEXEC,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)) >= 0)
+ const int flags= (mode & ~O_CREAT) | O_TMPFILE | O_CLOEXEC;
+ const mode_t open_mode= S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
+# ifdef O_DIRECT
+ static int O_TMPFILE_works_with_O_DIRECT= O_DIRECT;
+ const int try_O_DIRECT= mode & O_TMPFILE_works_with_O_DIRECT;
+ if (try_O_DIRECT)
+ file= open(dir, flags | O_DIRECT, open_mode);
+ else
+# endif
+ file= open(dir, flags, open_mode);
+
+ if (file >= 0)
{
+# ifdef O_DIRECT
+ O_TMPFILE_works:
+# endif
my_snprintf(to, FN_REFLEN, "%s/#sql/fd=%d", dir, file);
file=my_register_filename(file, to, FILE_BY_O_TMPFILE,
EE_CANTCREATEFILE, MyFlags);
}
+# ifdef O_DIRECT
+ else if (errno == EINVAL && try_O_DIRECT)
+ {
+ file= open(dir, flags, open_mode);
+ if (file >= 0)
+ {
+ O_TMPFILE_works_with_O_DIRECT= 0;
+ goto O_TMPFILE_works;
+ }
+ }
+# endif
else if (errno == EOPNOTSUPP || errno == EINVAL)
{
my_printf_error(EE_CANTCREATEFILE, "O_TMPFILE is not supported on %s "