mirror of
https://github.com/MariaDB/server.git
synced 2025-10-12 12:25:37 +03:00
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
This commit is contained in:
committed by
Sergei Golubchik
parent
ced6638773
commit
3edac3f18d
@@ -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
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user