diff options
author | Daniel Black <daniel@linux.ibm.com> | 2018-05-21 09:51:45 +1000 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2018-06-04 12:32:23 +0200 |
commit | 3edac3f18d2d74f68e6f9f9b41e5d05a5c8ca9c5 (patch) | |
tree | e8981d0eba8aacecd684f6715a147a22a97c233b | |
parent | ced66387734325304e0a3dc932ad709c125ccb50 (diff) | |
download | mariadb-git-3edac3f18d2d74f68e6f9f9b41e5d05a5c8ca9c5.tar.gz |
MDEV-15584 Linux use O_TMPFILE
O_TMPFILE creates a tempfile not attached to a filename.
This is what we want for MY_TEMPORARY.
We preserve a state O_TMPFILE_works, because kernel version or
filesystem could cause failure.
Closes #662
-rw-r--r-- | include/my_sys.h | 2 | ||||
-rw-r--r-- | mysys/mf_tempfile.c | 27 |
2 files changed, 28 insertions, 1 deletions
diff --git a/include/my_sys.h b/include/my_sys.h index 40cbe1d12e8..325c473eb23 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -328,7 +328,7 @@ typedef struct st_record_cache /* Used when caching records */ enum file_type { UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE, STREAM_BY_FOPEN, STREAM_BY_FDOPEN, - FILE_BY_MKSTEMP, FILE_BY_DUP + FILE_BY_O_TMPFILE, FILE_BY_MKSTEMP, FILE_BY_DUP }; struct st_my_file_info diff --git a/mysys/mf_tempfile.c b/mysys/mf_tempfile.c index e6c19a25789..54b0d85b552 100644 --- a/mysys/mf_tempfile.c +++ b/mysys/mf_tempfile.c @@ -110,6 +110,33 @@ File create_temp_file(char *to, const char *dir, const char *prefix, } } #elif defined(HAVE_MKSTEMP) +#ifdef O_TMPFILE + { + static int O_TMPFILE_works= 1; + + if ((MyFlags & MY_TEMPORARY) && O_TMPFILE_works) + { + /* explictly don't use O_EXCL here has it has a different + meaning with O_TMPFILE + */ + if ((file= open(dir, mode | O_TMPFILE | O_CLOEXEC, + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)) >= 0) + { + my_snprintf(to, FN_REFLEN, "%s/#sql/fd=%d", dir, file); + file=my_register_filename(file, to, FILE_BY_O_TMPFILE, + EE_CANTCREATEFILE, MyFlags); + } + else if (errno == EOPNOTSUPP || errno == EINVAL) + { + my_printf_error(EE_CANTCREATEFILE, "O_TMPFILE is not supported on %s " + "(disabling future attempts)", + MYF(ME_NOTE | ME_ERROR_LOG_ONLY), dir); + O_TMPFILE_works= 0; + } + } + } + if (file == -1) +#endif /* O_TMPFILE */ { char prefix_buff[30]; uint pfx_len; |