Commit 3dd7b0a8 authored by Marko Mäkelä's avatar Marko Mäkelä

Cleanup: Remove OS_FILE_ON_ERROR_NO_EXIT

Ever since commit 412ee033
or commit a440d6ed
InnoDB should generally not abort when failing to open or create files.
In Datafile::open_or_create() we had failed to set the flag
to avoid abort() on failure, but everywhere else we were setting it.

We may still call abort() via os_file_handle_error().

Reviewed by: Vladislav Vaintroub
parent 7f7329f0
...@@ -1900,8 +1900,7 @@ inline void log_t::write_checkpoint(lsn_t end_lsn) noexcept ...@@ -1900,8 +1900,7 @@ inline void log_t::write_checkpoint(lsn_t end_lsn) noexcept
ut_ad(!log.is_opened()); ut_ad(!log.is_opened());
bool success; bool success;
log.m_file= log.m_file=
os_file_create_func(get_log_file_path().c_str(), os_file_create_func(get_log_file_path().c_str(), OS_FILE_OPEN,
OS_FILE_OPEN | OS_FILE_ON_ERROR_NO_EXIT,
OS_FILE_NORMAL, OS_LOG_FILE, false, &success); OS_FILE_NORMAL, OS_LOG_FILE, false, &success);
ut_a(success); ut_a(success);
ut_a(log.is_opened()); ut_a(log.is_opened());
......
...@@ -361,8 +361,7 @@ static bool fil_node_open_file_low(fil_node_t *node) ...@@ -361,8 +361,7 @@ static bool fil_node_open_file_low(fil_node_t *node)
bool success; bool success;
node->handle= os_file_create(innodb_data_file_key, node->name, node->handle= os_file_create(innodb_data_file_key, node->name,
node->is_raw_disk node->is_raw_disk
? OS_FILE_OPEN_RAW | OS_FILE_ON_ERROR_NO_EXIT ? OS_FILE_OPEN_RAW : OS_FILE_OPEN,
: OS_FILE_OPEN | OS_FILE_ON_ERROR_NO_EXIT,
OS_FILE_AIO, type, OS_FILE_AIO, type,
srv_read_only_mode, &success); srv_read_only_mode, &success);
...@@ -1922,7 +1921,7 @@ fil_ibd_create( ...@@ -1922,7 +1921,7 @@ fil_ibd_create(
file = os_file_create( file = os_file_create(
innodb_data_file_key, path, innodb_data_file_key, path,
OS_FILE_CREATE | OS_FILE_ON_ERROR_NO_EXIT, OS_FILE_CREATE,
OS_FILE_AIO, type, srv_read_only_mode, &success); OS_FILE_AIO, type, srv_read_only_mode, &success);
if (!success) { if (!success) {
......
...@@ -109,22 +109,21 @@ struct pfs_os_file_t ...@@ -109,22 +109,21 @@ struct pfs_os_file_t
/** Options for os_file_create_func @{ */ /** Options for os_file_create_func @{ */
enum os_file_create_t { enum os_file_create_t {
OS_FILE_OPEN = 51, /*!< to open an existing file (if /** create a new file */
doesn't exist, error) */ OS_FILE_CREATE= 0,
OS_FILE_CREATE, /*!< to create new file (if /** open an existing file */
exists, error) */ OS_FILE_OPEN,
OS_FILE_OPEN_RAW, /*!< to open a raw device or disk /** retry opening an existing file */
partition */ OS_FILE_OPEN_RETRY,
OS_FILE_OPEN_RETRY, /*!< open with retry */ /** open a raw block device */
OS_FILE_OPEN_RAW,
/** Flags that can be combined with the above values. Please ensure
that the above values stay below 128. */ /** do not display diagnostic messages */
OS_FILE_ON_ERROR_SILENT= 4,
OS_FILE_ON_ERROR_NO_EXIT = 128, /*!< do not exit on unknown errors */
OS_FILE_ON_ERROR_SILENT = 256 /*!< don't print diagnostic messages to OS_FILE_CREATE_SILENT= OS_FILE_CREATE | OS_FILE_ON_ERROR_SILENT,
the log unless it is a fatal error, OS_FILE_OPEN_SILENT= OS_FILE_OPEN | OS_FILE_ON_ERROR_SILENT,
this flag is only used if OS_FILE_OPEN_RETRY_SILENT= OS_FILE_OPEN_RETRY | OS_FILE_ON_ERROR_SILENT
ON_ERROR_NO_EXIT is set */
}; };
static const ulint OS_FILE_READ_ONLY = 333; static const ulint OS_FILE_READ_ONLY = 333;
...@@ -346,7 +345,7 @@ A simple function to open or create a file. ...@@ -346,7 +345,7 @@ A simple function to open or create a file.
pfs_os_file_t pfs_os_file_t
os_file_create_simple_func( os_file_create_simple_func(
const char* name, const char* name,
ulint create_mode, os_file_create_t create_mode,
ulint access_type, ulint access_type,
bool read_only, bool read_only,
bool* success); bool* success);
...@@ -355,7 +354,7 @@ os_file_create_simple_func( ...@@ -355,7 +354,7 @@ os_file_create_simple_func(
os_file_create_simple_no_error_handling(), not directly this function! os_file_create_simple_no_error_handling(), not directly this function!
A simple function to open or create a file. A simple function to open or create a file.
@param[in] name name of the file or path as a null-terminated string @param[in] name name of the file or path as a null-terminated string
@param[in] create_mode create mode @param[in] create_mode OS_FILE_CREATE or OS_FILE_OPEN
@param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or @param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or
OS_FILE_READ_ALLOW_DELETE; the last option OS_FILE_READ_ALLOW_DELETE; the last option
is used by a backup program reading the file is used by a backup program reading the file
...@@ -366,7 +365,7 @@ A simple function to open or create a file. ...@@ -366,7 +365,7 @@ A simple function to open or create a file.
pfs_os_file_t pfs_os_file_t
os_file_create_simple_no_error_handling_func( os_file_create_simple_no_error_handling_func(
const char* name, const char* name,
ulint create_mode, os_file_create_t create_mode,
ulint access_type, ulint access_type,
bool read_only, bool read_only,
bool* success) bool* success)
...@@ -400,7 +399,7 @@ Opens an existing file or creates a new. ...@@ -400,7 +399,7 @@ Opens an existing file or creates a new.
pfs_os_file_t pfs_os_file_t
os_file_create_func( os_file_create_func(
const char* name, const char* name,
ulint create_mode, os_file_create_t create_mode,
ulint purpose, ulint purpose,
ulint type, ulint type,
bool read_only, bool read_only,
...@@ -598,7 +597,7 @@ pfs_os_file_t ...@@ -598,7 +597,7 @@ pfs_os_file_t
pfs_os_file_create_simple_func( pfs_os_file_create_simple_func(
mysql_pfs_key_t key, mysql_pfs_key_t key,
const char* name, const char* name,
ulint create_mode, os_file_create_t create_mode,
ulint access_type, ulint access_type,
bool read_only, bool read_only,
bool* success, bool* success,
...@@ -614,7 +613,7 @@ monitor file creation/open. ...@@ -614,7 +613,7 @@ monitor file creation/open.
@param[in] key Performance Schema Key @param[in] key Performance Schema Key
@param[in] name name of the file or path as a null-terminated @param[in] name name of the file or path as a null-terminated
string string
@param[in] create_mode create mode @param[in] create_mode OS_FILE_CREATE or OS_FILE_OPEN
@param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or @param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or
OS_FILE_READ_ALLOW_DELETE; the last option is OS_FILE_READ_ALLOW_DELETE; the last option is
used by a backup program reading the file used by a backup program reading the file
...@@ -629,7 +628,7 @@ pfs_os_file_t ...@@ -629,7 +628,7 @@ pfs_os_file_t
pfs_os_file_create_simple_no_error_handling_func( pfs_os_file_create_simple_no_error_handling_func(
mysql_pfs_key_t key, mysql_pfs_key_t key,
const char* name, const char* name,
ulint create_mode, os_file_create_t create_mode,
ulint access_type, ulint access_type,
bool read_only, bool read_only,
bool* success, bool* success,
...@@ -662,7 +661,7 @@ pfs_os_file_t ...@@ -662,7 +661,7 @@ pfs_os_file_t
pfs_os_file_create_func( pfs_os_file_create_func(
mysql_pfs_key_t key, mysql_pfs_key_t key,
const char* name, const char* name,
ulint create_mode, os_file_create_t create_mode,
ulint purpose, ulint purpose,
ulint type, ulint type,
bool read_only, bool read_only,
......
...@@ -45,7 +45,7 @@ pfs_os_file_t ...@@ -45,7 +45,7 @@ pfs_os_file_t
pfs_os_file_create_simple_func( pfs_os_file_create_simple_func(
mysql_pfs_key_t key, mysql_pfs_key_t key,
const char* name, const char* name,
ulint create_mode, os_file_create_t create_mode,
ulint access_type, ulint access_type,
bool read_only, bool read_only,
bool* success, bool* success,
...@@ -80,7 +80,7 @@ monitor file creation/open. ...@@ -80,7 +80,7 @@ monitor file creation/open.
@param[in] key Performance Schema Key @param[in] key Performance Schema Key
@param[in] name name of the file or path as a null-terminated @param[in] name name of the file or path as a null-terminated
string string
@param[in] create_mode create mode @param[in] create_mode OS_FILE_CREATE or OS_FILE_OPEN
@param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or @param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or
OS_FILE_READ_ALLOW_DELETE; the last option is OS_FILE_READ_ALLOW_DELETE; the last option is
used by a backup program reading the file used by a backup program reading the file
...@@ -95,7 +95,7 @@ pfs_os_file_t ...@@ -95,7 +95,7 @@ pfs_os_file_t
pfs_os_file_create_simple_no_error_handling_func( pfs_os_file_create_simple_no_error_handling_func(
mysql_pfs_key_t key, mysql_pfs_key_t key,
const char* name, const char* name,
ulint create_mode, os_file_create_t create_mode,
ulint access_type, ulint access_type,
bool read_only, bool read_only,
bool* success, bool* success,
...@@ -146,7 +146,7 @@ pfs_os_file_t ...@@ -146,7 +146,7 @@ pfs_os_file_t
pfs_os_file_create_func( pfs_os_file_create_func(
mysql_pfs_key_t key, mysql_pfs_key_t key,
const char* name, const char* name,
ulint create_mode, os_file_create_t create_mode,
ulint purpose, ulint purpose,
ulint type, ulint type,
bool read_only, bool read_only,
......
...@@ -466,8 +466,7 @@ log_t::resize_start_status log_t::resize_start(os_offset_t size) noexcept ...@@ -466,8 +466,7 @@ log_t::resize_start_status log_t::resize_start(os_offset_t size) noexcept
resize_lsn.store(1, std::memory_order_relaxed); resize_lsn.store(1, std::memory_order_relaxed);
resize_target= 0; resize_target= 0;
resize_log.m_file= resize_log.m_file=
os_file_create_func(path.c_str(), os_file_create_func(path.c_str(), OS_FILE_CREATE,
OS_FILE_CREATE | OS_FILE_ON_ERROR_NO_EXIT,
OS_FILE_NORMAL, OS_LOG_FILE, false, &success); OS_FILE_NORMAL, OS_LOG_FILE, false, &success);
if (success) if (success)
{ {
......
...@@ -844,8 +844,7 @@ static struct ...@@ -844,8 +844,7 @@ static struct
inside recv_sys_t::recover_deferred(). */ inside recv_sys_t::recover_deferred(). */
bool success; bool success;
handle= os_file_create(innodb_data_file_key, filename, handle= os_file_create(innodb_data_file_key, filename,
OS_FILE_CREATE | OS_FILE_ON_ERROR_NO_EXIT | OS_FILE_CREATE_SILENT,
OS_FILE_ON_ERROR_SILENT,
OS_FILE_AIO, OS_DATA_FILE, false, &success); OS_FILE_AIO, OS_DATA_FILE, false, &success);
} }
space->add(filename, handle, size, false, false); space->add(filename, handle, size, false, false);
...@@ -1714,7 +1713,7 @@ dberr_t recv_sys_t::find_checkpoint() ...@@ -1714,7 +1713,7 @@ dberr_t recv_sys_t::find_checkpoint()
std::string path{get_log_file_path()}; std::string path{get_log_file_path()};
bool success; bool success;
os_file_t file{os_file_create_func(path.c_str(), os_file_t file{os_file_create_func(path.c_str(),
OS_FILE_OPEN | OS_FILE_ON_ERROR_NO_EXIT, OS_FILE_OPEN,
OS_FILE_NORMAL, OS_LOG_FILE, OS_FILE_NORMAL, OS_LOG_FILE,
srv_read_only_mode, &success)}; srv_read_only_mode, &success)};
if (file == OS_FILE_CLOSED) if (file == OS_FILE_CLOSED)
...@@ -1744,8 +1743,7 @@ dberr_t recv_sys_t::find_checkpoint() ...@@ -1744,8 +1743,7 @@ dberr_t recv_sys_t::find_checkpoint()
{ {
path= get_log_file_path(LOG_FILE_NAME_PREFIX).append(std::to_string(i)); path= get_log_file_path(LOG_FILE_NAME_PREFIX).append(std::to_string(i));
file= os_file_create_func(path.c_str(), file= os_file_create_func(path.c_str(),
OS_FILE_OPEN | OS_FILE_ON_ERROR_NO_EXIT | OS_FILE_OPEN_SILENT,
OS_FILE_ON_ERROR_SILENT,
OS_FILE_NORMAL, OS_LOG_FILE, true, &success); OS_FILE_NORMAL, OS_LOG_FILE, true, &success);
if (file == OS_FILE_CLOSED) if (file == OS_FILE_CLOSED)
break; break;
......
...@@ -200,17 +200,10 @@ os_file_handle_error_cond_exit( ...@@ -200,17 +200,10 @@ os_file_handle_error_cond_exit(
bool on_error_silent); bool on_error_silent);
/** Does error handling when a file operation fails. /** Does error handling when a file operation fails.
@param[in] name name of a file or NULL @param operation name of operation that failed */
@param[in] operation operation name that failed static void os_file_handle_error(const char *operation)
@return true if we should retry the operation */
static
bool
os_file_handle_error(
const char* name,
const char* operation)
{ {
/* Exit in case of unknown error */ os_file_handle_error_cond_exit(nullptr, operation, true, false);
return(os_file_handle_error_cond_exit(name, operation, true, false));
} }
/** Does error handling when a file operation fails. /** Does error handling when a file operation fails.
...@@ -942,7 +935,7 @@ os_file_flush_func( ...@@ -942,7 +935,7 @@ os_file_flush_func(
ib::error() << "The OS said file flush did not succeed"; ib::error() << "The OS said file flush did not succeed";
os_file_handle_error(NULL, "flush"); os_file_handle_error("flush");
/* It is a fatal error if a file flush does not succeed, because then /* It is a fatal error if a file flush does not succeed, because then
the database can get corrupt on disk */ the database can get corrupt on disk */
...@@ -965,7 +958,7 @@ A simple function to open or create a file. ...@@ -965,7 +958,7 @@ A simple function to open or create a file.
pfs_os_file_t pfs_os_file_t
os_file_create_simple_func( os_file_create_simple_func(
const char* name, const char* name,
ulint create_mode, os_file_create_t create_mode,
ulint access_type, ulint access_type,
bool read_only, bool read_only,
bool* success) bool* success)
...@@ -976,23 +969,14 @@ os_file_create_simple_func( ...@@ -976,23 +969,14 @@ os_file_create_simple_func(
int create_flag = O_RDONLY | O_CLOEXEC; int create_flag = O_RDONLY | O_CLOEXEC;
ut_a(!(create_mode & OS_FILE_ON_ERROR_SILENT));
ut_a(!(create_mode & OS_FILE_ON_ERROR_NO_EXIT));
if (read_only) { if (read_only) {
} else if (create_mode == OS_FILE_OPEN) {
if (access_type != OS_FILE_READ_ONLY) {
create_flag = O_RDWR | O_CLOEXEC;
}
} else if (create_mode == OS_FILE_CREATE) { } else if (create_mode == OS_FILE_CREATE) {
create_flag = O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC; create_flag = O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC;
} else { } else {
ib::error() ut_ad(create_mode == OS_FILE_OPEN);
<< "Unknown file create mode (" if (access_type != OS_FILE_READ_ONLY) {
<< create_mode create_flag = O_RDWR | O_CLOEXEC;
<< " for file '" << name << "'"; }
return(OS_FILE_CLOSED);
} }
bool retry; bool retry;
...@@ -1025,10 +1009,10 @@ os_file_create_simple_func( ...@@ -1025,10 +1009,10 @@ os_file_create_simple_func(
} }
#endif #endif
*success = false; *success = false;
retry = os_file_handle_error( retry = os_file_handle_error_no_exit(
name, name,
create_mode == OS_FILE_OPEN create_mode == OS_FILE_CREATE
? "open" : "create"); ? "create" : "open", false);
} else { } else {
*success = true; *success = true;
retry = false; retry = false;
...@@ -1154,48 +1138,34 @@ Opens an existing file or creates a new. ...@@ -1154,48 +1138,34 @@ Opens an existing file or creates a new.
pfs_os_file_t pfs_os_file_t
os_file_create_func( os_file_create_func(
const char* name, const char* name,
ulint create_mode, os_file_create_t create_mode,
ulint purpose, ulint purpose,
ulint type, ulint type,
bool read_only, bool read_only,
bool* success) bool* success)
{ {
bool on_error_no_exit;
bool on_error_silent;
*success = false; *success = false;
DBUG_EXECUTE_IF( DBUG_EXECUTE_IF(
"ib_create_table_fail_disk_full", "ib_create_table_fail_disk_full",
*success = false;
errno = ENOSPC; errno = ENOSPC;
return(OS_FILE_CLOSED); return(OS_FILE_CLOSED);
); );
int create_flag; int create_flag;
on_error_no_exit = create_mode & OS_FILE_ON_ERROR_NO_EXIT
? true : false;
on_error_silent = create_mode & OS_FILE_ON_ERROR_SILENT
? true : false;
create_mode &= ulint(~(OS_FILE_ON_ERROR_NO_EXIT
| OS_FILE_ON_ERROR_SILENT));
if (read_only) { if (read_only) {
create_flag = O_RDONLY | O_CLOEXEC; create_flag = O_RDONLY | O_CLOEXEC;
} else if (create_mode == OS_FILE_OPEN } else if (create_mode == OS_FILE_CREATE
|| create_mode == OS_FILE_OPEN_RAW || create_mode == OS_FILE_CREATE_SILENT) {
|| create_mode == OS_FILE_OPEN_RETRY) {
create_flag = O_RDWR | O_CLOEXEC;
} else if (create_mode == OS_FILE_CREATE) {
create_flag = O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC; create_flag = O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC;
} else { } else {
ib::error() ut_ad(create_mode == OS_FILE_OPEN
<< "Unknown file create mode (" << create_mode << ")" || create_mode == OS_FILE_OPEN_SILENT
<< " for file '" << name << "'"; || create_mode == OS_FILE_OPEN_RETRY
|| create_mode == OS_FILE_OPEN_RETRY_SILENT
return(OS_FILE_CLOSED); || create_mode == OS_FILE_OPEN_RAW);
create_flag = O_RDWR | O_CLOEXEC;
} }
#ifdef O_DIRECT #ifdef O_DIRECT
...@@ -1219,10 +1189,14 @@ os_file_create_func( ...@@ -1219,10 +1189,14 @@ os_file_create_func(
} else if (log_sys.log_buffered) { } else if (log_sys.log_buffered) {
skip_o_direct: skip_o_direct:
os_file_log_buffered(); os_file_log_buffered();
} else if (create_mode != OS_FILE_CREATE && !log_sys.is_opened()) { } else if (create_mode != OS_FILE_CREATE
&& create_mode != OS_FILE_CREATE_SILENT
&& !log_sys.is_opened()) {
if (stat(name, &st)) { if (stat(name, &st)) {
if (errno == ENOENT) { if (errno == ENOENT) {
if (on_error_silent) goto not_found; if (create_mode & OS_FILE_ON_ERROR_SILENT) {
goto not_found;
}
sql_print_error( sql_print_error(
"InnoDB: File %s was not found", name); "InnoDB: File %s was not found", name);
goto not_found; goto not_found;
...@@ -1256,9 +1230,8 @@ os_file_create_func( ...@@ -1256,9 +1230,8 @@ os_file_create_func(
} }
os_file_t file; os_file_t file;
bool retry;
do { for (;;) {
file = open(name, create_flag | direct_flag, os_innodb_umask); file = open(name, create_flag | direct_flag, os_innodb_umask);
if (file == -1) { if (file == -1) {
...@@ -1270,34 +1243,26 @@ os_file_create_func( ...@@ -1270,34 +1243,26 @@ os_file_create_func(
os_file_log_buffered(); os_file_log_buffered();
} }
# endif # endif
if (create_mode == OS_FILE_CREATE) { if (create_mode == OS_FILE_CREATE
|| create_mode == OS_FILE_CREATE_SILENT) {
/* Linux may create the file /* Linux may create the file
before rejecting the O_DIRECT. */ before rejecting the O_DIRECT. */
unlink(name); unlink(name);
} }
retry = true;
continue; continue;
} }
#endif #endif
const char* operation; if (!os_file_handle_error_no_exit(
name, (create_flag & O_CREAT)
operation = (create_mode == OS_FILE_CREATE ? "create" : "open",
&& !read_only) ? "create" : "open"; create_mode & OS_FILE_ON_ERROR_SILENT)) {
break;
*success = false;
if (on_error_no_exit) {
retry = os_file_handle_error_no_exit(
name, operation, on_error_silent);
} else {
retry = os_file_handle_error(name, operation);
} }
} else { } else {
*success = true; *success = true;
retry = false; break;
} }
}
} while (retry);
if (!*success) { if (!*success) {
#ifdef __linux__ #ifdef __linux__
...@@ -1307,8 +1272,7 @@ os_file_create_func( ...@@ -1307,8 +1272,7 @@ os_file_create_func(
} }
#ifdef __linux__ #ifdef __linux__
if (!read_only && create_mode == OS_FILE_CREATE if ((create_flag & O_CREAT) && type == OS_LOG_FILE) {
&& type == OS_LOG_FILE) {
if (fstat(file, &st) || !os_file_log_maybe_unbuffered(st)) { if (fstat(file, &st) || !os_file_log_maybe_unbuffered(st)) {
os_file_log_buffered(); os_file_log_buffered();
} else { } else {
...@@ -1324,7 +1288,8 @@ os_file_create_func( ...@@ -1324,7 +1288,8 @@ os_file_create_func(
&& !my_disable_locking && !my_disable_locking
&& os_file_lock(file, name)) { && os_file_lock(file, name)) {
if (create_mode == OS_FILE_OPEN_RETRY) { if (create_mode == OS_FILE_OPEN_RETRY
|| create_mode == OS_FILE_OPEN_RETRY_SILENT) {
ib::info() ib::info()
<< "Retrying to lock the first data file"; << "Retrying to lock the first data file";
...@@ -1355,7 +1320,7 @@ os_file_create_simple_no_error_handling(), not directly this function! ...@@ -1355,7 +1320,7 @@ os_file_create_simple_no_error_handling(), not directly this function!
A simple function to open or create a file. A simple function to open or create a file.
@param[in] name name of the file or path as a null-terminated @param[in] name name of the file or path as a null-terminated
string string
@param[in] create_mode create mode @param[in] create_mode OS_FILE_CREATE or OS_FILE_OPEN
@param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or @param[in] access_type OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or
OS_FILE_READ_ALLOW_DELETE; the last option OS_FILE_READ_ALLOW_DELETE; the last option
is used by a backup program reading the file is used by a backup program reading the file
...@@ -1366,7 +1331,7 @@ A simple function to open or create a file. ...@@ -1366,7 +1331,7 @@ A simple function to open or create a file.
pfs_os_file_t pfs_os_file_t
os_file_create_simple_no_error_handling_func( os_file_create_simple_no_error_handling_func(
const char* name, const char* name,
ulint create_mode, os_file_create_t create_mode,
ulint access_type, ulint access_type,
bool read_only, bool read_only,
bool* success) bool* success)
...@@ -1374,30 +1339,19 @@ os_file_create_simple_no_error_handling_func( ...@@ -1374,30 +1339,19 @@ os_file_create_simple_no_error_handling_func(
os_file_t file; os_file_t file;
int create_flag = O_RDONLY | O_CLOEXEC; int create_flag = O_RDONLY | O_CLOEXEC;
ut_a(!(create_mode & OS_FILE_ON_ERROR_SILENT));
ut_a(!(create_mode & OS_FILE_ON_ERROR_NO_EXIT));
*success = false; *success = false;
if (read_only) { if (read_only) {
} else if (create_mode == OS_FILE_OPEN) { } else if (create_mode == OS_FILE_CREATE) {
create_flag = O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC;
} else {
ut_ad(create_mode == OS_FILE_OPEN);
if (access_type != OS_FILE_READ_ONLY) { if (access_type != OS_FILE_READ_ONLY) {
ut_a(access_type == OS_FILE_READ_WRITE ut_a(access_type == OS_FILE_READ_WRITE
|| access_type == OS_FILE_READ_ALLOW_DELETE); || access_type == OS_FILE_READ_ALLOW_DELETE);
create_flag = O_RDWR; create_flag = O_RDWR;
} }
} else if (create_mode == OS_FILE_CREATE) {
create_flag = O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC;
} else {
ib::error()
<< "Unknown file create mode "
<< create_mode << " for file '" << name << "'";
return(OS_FILE_CLOSED);
} }
file = open(name, create_flag, os_innodb_umask); file = open(name, create_flag, os_innodb_umask);
...@@ -1520,7 +1474,7 @@ bool os_file_close_func(os_file_t file) ...@@ -1520,7 +1474,7 @@ bool os_file_close_func(os_file_t file)
if (!ret) if (!ret)
return true; return true;
os_file_handle_error(NULL, "close"); os_file_handle_error("close");
return false; return false;
} }
...@@ -1793,7 +1747,7 @@ bool os_file_flush_func(os_file_t file) ...@@ -1793,7 +1747,7 @@ bool os_file_flush_func(os_file_t file)
if (srv_start_raw_disk_in_use && GetLastError() == ERROR_INVALID_FUNCTION) if (srv_start_raw_disk_in_use && GetLastError() == ERROR_INVALID_FUNCTION)
return true; return true;
os_file_handle_error(nullptr, "flush"); os_file_handle_error("flush");
/* It is a fatal error if a file flush does not succeed, because then /* It is a fatal error if a file flush does not succeed, because then
the database can get corrupt on disk */ the database can get corrupt on disk */
...@@ -1907,7 +1861,7 @@ A simple function to open or create a file. ...@@ -1907,7 +1861,7 @@ A simple function to open or create a file.
pfs_os_file_t pfs_os_file_t
os_file_create_simple_func( os_file_create_simple_func(
const char* name, const char* name,
ulint create_mode, os_file_create_t create_mode,
ulint access_type, ulint access_type,
bool read_only, bool read_only,
bool* success) bool* success)
...@@ -1916,65 +1870,31 @@ os_file_create_simple_func( ...@@ -1916,65 +1870,31 @@ os_file_create_simple_func(
*success = false; *success = false;
DWORD access; DWORD access = GENERIC_READ;
DWORD create_flag; DWORD create_flag;
DWORD attributes = 0; DWORD attributes = 0;
ut_a(!(create_mode & OS_FILE_ON_ERROR_SILENT));
ut_a(!(create_mode & OS_FILE_ON_ERROR_NO_EXIT));
ut_ad(srv_operation == SRV_OPERATION_NORMAL); ut_ad(srv_operation == SRV_OPERATION_NORMAL);
if (create_mode == OS_FILE_OPEN) { if (read_only || create_mode == OS_FILE_OPEN) {
create_flag = OPEN_EXISTING; create_flag = OPEN_EXISTING;
} else if (read_only) {
create_flag = OPEN_EXISTING;
} else if (create_mode == OS_FILE_CREATE) {
create_flag = CREATE_NEW;
} else { } else {
ut_ad(create_mode == OS_FILE_CREATE);
ib::error() create_flag = CREATE_NEW;
<< "Unknown file create mode ("
<< create_mode << ") for file '"
<< name << "'";
return(OS_FILE_CLOSED);
} }
if (access_type == OS_FILE_READ_ONLY) { if (access_type == OS_FILE_READ_ONLY) {
access = GENERIC_READ;
} else if (read_only) { } else if (read_only) {
ib::info() ib::info()
<< "Read only mode set. Unable to" << "Read only mode set. Unable to"
" open file '" << name << "' in RW mode, " " open file '" << name << "' in RW mode, "
<< "trying RO mode"; << "trying RO mode";
access = GENERIC_READ;
} else if (access_type == OS_FILE_READ_WRITE) {
access = GENERIC_READ | GENERIC_WRITE;
} else { } else {
ut_ad(access_type == OS_FILE_READ_WRITE);
ib::error() access = GENERIC_READ | GENERIC_WRITE;
<< "Unknown file access type (" << access_type << ") "
"for file '" << name << "'";
return(OS_FILE_CLOSED);
} }
bool retry; for (;;) {
do {
/* Use default security attributes and no template file. */ /* Use default security attributes and no template file. */
file = CreateFile( file = CreateFile(
...@@ -1982,22 +1902,18 @@ os_file_create_simple_func( ...@@ -1982,22 +1902,18 @@ os_file_create_simple_func(
FILE_SHARE_READ | FILE_SHARE_DELETE, FILE_SHARE_READ | FILE_SHARE_DELETE,
my_win_file_secattr(), create_flag, attributes, NULL); my_win_file_secattr(), create_flag, attributes, NULL);
if (file == INVALID_HANDLE_VALUE) { if (file != INVALID_HANDLE_VALUE) {
*success = false;
retry = os_file_handle_error(
name, create_mode == OS_FILE_OPEN ?
"open" : "create");
} else {
retry = false;
*success = true; *success = true;
break;
} }
} while (retry); if (!os_file_handle_error_no_exit(name,
create_flag == CREATE_NEW
? "create" : "open",
false)) {
break;
}
}
return(file); return(file);
} }
...@@ -2066,16 +1982,13 @@ Opens an existing file or creates a new. ...@@ -2066,16 +1982,13 @@ Opens an existing file or creates a new.
pfs_os_file_t pfs_os_file_t
os_file_create_func( os_file_create_func(
const char* name, const char* name,
ulint create_mode, os_file_create_t create_mode,
ulint purpose, ulint purpose,
ulint type, ulint type,
bool read_only, bool read_only,
bool* success) bool* success)
{ {
os_file_t file; os_file_t file;
bool retry;
bool on_error_no_exit;
bool on_error_silent;
*success = false; *success = false;
...@@ -2086,50 +1999,30 @@ os_file_create_func( ...@@ -2086,50 +1999,30 @@ os_file_create_func(
return(OS_FILE_CLOSED); return(OS_FILE_CLOSED);
); );
DWORD create_flag; DWORD create_flag = OPEN_EXISTING;
DWORD share_mode = read_only DWORD share_mode = read_only
? FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ? FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
: FILE_SHARE_READ | FILE_SHARE_DELETE; : FILE_SHARE_READ | FILE_SHARE_DELETE;
on_error_no_exit = create_mode & OS_FILE_ON_ERROR_NO_EXIT switch (create_mode) {
? true : false; case OS_FILE_OPEN_RAW:
on_error_silent = create_mode & OS_FILE_ON_ERROR_SILENT
? true : false;
create_mode &= ~(OS_FILE_ON_ERROR_NO_EXIT | OS_FILE_ON_ERROR_SILENT);
if (create_mode == OS_FILE_OPEN_RAW) {
ut_a(!read_only); ut_a(!read_only);
/* On Windows Physical devices require admin privileges and /* On Windows Physical devices require admin privileges and
have to have the write-share mode set. See the remarks have to have the write-share mode set. See the remarks
section for the CreateFile() function documentation in MSDN. */ section for the CreateFile() function documentation in MSDN. */
share_mode |= FILE_SHARE_WRITE; share_mode |= FILE_SHARE_WRITE;
break;
create_flag = OPEN_EXISTING; case OS_FILE_CREATE_SILENT:
case OS_FILE_CREATE:
} else if (create_mode == OS_FILE_OPEN
|| create_mode == OS_FILE_OPEN_RETRY) {
create_flag = OPEN_EXISTING;
} else if (read_only) {
create_flag = OPEN_EXISTING;
} else if (create_mode == OS_FILE_CREATE) {
create_flag = CREATE_NEW; create_flag = CREATE_NEW;
break;
} else { default:
ib::error() ut_ad(create_mode == OS_FILE_OPEN
<< "Unknown file create mode (" << create_mode << ") " || create_mode == OS_FILE_OPEN_SILENT
<< " for file '" << name << "'"; || create_mode == OS_FILE_OPEN_RETRY_SILENT
|| create_mode == OS_FILE_OPEN_RETRY);
return(OS_FILE_CLOSED); break;
} }
DWORD attributes = (purpose == OS_FILE_AIO && srv_use_native_aio) DWORD attributes = (purpose == OS_FILE_AIO && srv_use_native_aio)
...@@ -2187,18 +2080,11 @@ os_file_create_func( ...@@ -2187,18 +2080,11 @@ os_file_create_func(
break; break;
} }
operation = (create_mode == OS_FILE_CREATE && !read_only) ? operation = create_flag == CREATE_NEW ? "create" : "open";
"create" : "open";
if (on_error_no_exit) { if (!os_file_handle_error_no_exit(name, operation,
retry = os_file_handle_error_no_exit( create_mode
name, operation, on_error_silent); & OS_FILE_ON_ERROR_SILENT)) {
}
else {
retry = os_file_handle_error(name, operation);
}
if (!retry) {
break; break;
} }
} }
...@@ -2225,79 +2111,42 @@ A simple function to open or create a file. ...@@ -2225,79 +2111,42 @@ A simple function to open or create a file.
pfs_os_file_t pfs_os_file_t
os_file_create_simple_no_error_handling_func( os_file_create_simple_no_error_handling_func(
const char* name, const char* name,
ulint create_mode, os_file_create_t create_mode,
ulint access_type, ulint access_type,
bool read_only, bool read_only,
bool* success) bool* success)
{ {
os_file_t file; os_file_t file;
*success = false; DWORD access = GENERIC_READ;
DWORD create_flag = OPEN_EXISTING;
DWORD access;
DWORD create_flag;
DWORD attributes = 0; DWORD attributes = 0;
DWORD share_mode = read_only DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_DELETE;
? FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE
: FILE_SHARE_READ | FILE_SHARE_DELETE;
ut_a(name); ut_a(name);
ut_a(!(create_mode & OS_FILE_ON_ERROR_SILENT)); if (read_only) {
ut_a(!(create_mode & OS_FILE_ON_ERROR_NO_EXIT)); share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE
| FILE_SHARE_DELETE;
if (create_mode == OS_FILE_OPEN) {
create_flag = OPEN_EXISTING;
} else if (read_only) {
create_flag = OPEN_EXISTING;
} else if (create_mode == OS_FILE_CREATE) {
create_flag = CREATE_NEW;
} else {
ib::error()
<< "Unknown file create mode (" << create_mode << ") "
<< " for file '" << name << "'";
return(OS_FILE_CLOSED);
}
if (access_type == OS_FILE_READ_ONLY) {
access = GENERIC_READ;
} else if (read_only) {
access = GENERIC_READ;
} else if (access_type == OS_FILE_READ_WRITE) {
access = GENERIC_READ | GENERIC_WRITE;
} else if (access_type == OS_FILE_READ_ALLOW_DELETE) {
ut_a(!read_only);
access = GENERIC_READ;
/*!< A backup program has to give mysqld the maximum
freedom to do what it likes with the file */
share_mode |= FILE_SHARE_DELETE | FILE_SHARE_WRITE
| FILE_SHARE_READ;
} else { } else {
if (create_mode == OS_FILE_CREATE) {
create_flag = CREATE_NEW;
} else {
ut_ad(create_mode == OS_FILE_OPEN);
}
ib::error() switch (access_type) {
<< "Unknown file access type (" << access_type << ") " case OS_FILE_READ_ONLY: break;
<< "for file '" << name << "'"; case OS_FILE_READ_WRITE:
access = GENERIC_READ | GENERIC_WRITE;
return(OS_FILE_CLOSED); break;
default:
ut_ad(access_type == OS_FILE_READ_ALLOW_DELETE);
/* A backup program has to give mariadbd the maximum
freedom to do what it likes with the file */
share_mode |= FILE_SHARE_DELETE | FILE_SHARE_WRITE
| FILE_SHARE_READ;
}
} }
file = CreateFile((LPCTSTR) name, file = CreateFile((LPCTSTR) name,
...@@ -2465,7 +2314,7 @@ bool os_file_close_func(os_file_t file) ...@@ -2465,7 +2314,7 @@ bool os_file_close_func(os_file_t file)
ut_ad(file); ut_ad(file);
if (!CloseHandle(file)) if (!CloseHandle(file))
{ {
os_file_handle_error(NULL, "close"); os_file_handle_error("close");
return false; return false;
} }
...@@ -2903,8 +2752,8 @@ os_file_read_func( ...@@ -2903,8 +2752,8 @@ os_file_read_func(
if (ulint(n_bytes) == n || err != DB_SUCCESS) if (ulint(n_bytes) == n || err != DB_SUCCESS)
return err; return err;
os_file_handle_error_cond_exit(type.node ? type.node->name : nullptr, "read", os_file_handle_error_no_exit(type.node ? type.node->name : nullptr, "read",
false, false); false);
sql_print_error("InnoDB: Tried to read %zu bytes at offset %llu" sql_print_error("InnoDB: Tried to read %zu bytes at offset %llu"
" of file %s, but was only able to read %zd", " of file %s, but was only able to read %zd",
n, offset, type.node ? type.node->name : "(unknown)", n, offset, type.node ? type.node->name : "(unknown)",
...@@ -3791,8 +3640,9 @@ dberr_t os_aio(const IORequest &type, void *buf, os_offset_t offset, size_t n) ...@@ -3791,8 +3640,9 @@ dberr_t os_aio(const IORequest &type, void *buf, os_offset_t offset, size_t n)
if (srv_thread_pool->submit_io(cb)) { if (srv_thread_pool->submit_io(cb)) {
slots->release(cb); slots->release(cb);
os_file_handle_error(type.node->name, type.is_read() os_file_handle_error_no_exit(type.node->name, type.is_read()
? "aio read" : "aio write"); ? "aio read" : "aio write",
false);
err = DB_IO_ERROR; err = DB_IO_ERROR;
type.node->space->release(); type.node->space->release();
} }
......
...@@ -201,7 +201,7 @@ static dberr_t create_log_file(bool create_new_db, lsn_t lsn) ...@@ -201,7 +201,7 @@ static dberr_t create_log_file(bool create_new_db, lsn_t lsn)
bool ret; bool ret;
os_file_t file{ os_file_t file{
os_file_create_func(logfile0.c_str(), os_file_create_func(logfile0.c_str(),
OS_FILE_CREATE | OS_FILE_ON_ERROR_NO_EXIT, OS_FILE_CREATE,
OS_FILE_NORMAL, OS_LOG_FILE, false, &ret) OS_FILE_NORMAL, OS_LOG_FILE, false, &ret)
}; };
...@@ -632,9 +632,8 @@ static uint32_t srv_undo_tablespace_open(bool create, const char* name, ...@@ -632,9 +632,8 @@ static uint32_t srv_undo_tablespace_open(bool create, const char* name,
} }
} }
pfs_os_file_t fh= os_file_create(innodb_data_file_key, name, OS_FILE_OPEN | pfs_os_file_t fh= os_file_create(innodb_data_file_key, name,
OS_FILE_ON_ERROR_NO_EXIT | OS_FILE_OPEN_SILENT,
OS_FILE_ON_ERROR_SILENT,
OS_FILE_AIO, OS_DATA_FILE, OS_FILE_AIO, OS_DATA_FILE,
srv_read_only_mode, &success); srv_read_only_mode, &success);
...@@ -731,9 +730,7 @@ srv_check_undo_redo_logs_exists() ...@@ -731,9 +730,7 @@ srv_check_undo_redo_logs_exists()
fh = os_file_create_func( fh = os_file_create_func(
name, name,
OS_FILE_OPEN_RETRY OS_FILE_OPEN_RETRY_SILENT,
| OS_FILE_ON_ERROR_NO_EXIT
| OS_FILE_ON_ERROR_SILENT,
OS_FILE_NORMAL, OS_FILE_NORMAL,
OS_DATA_FILE, OS_DATA_FILE,
srv_read_only_mode, srv_read_only_mode,
...@@ -755,8 +752,7 @@ srv_check_undo_redo_logs_exists() ...@@ -755,8 +752,7 @@ srv_check_undo_redo_logs_exists()
auto logfilename = get_log_file_path(); auto logfilename = get_log_file_path();
fh = os_file_create_func(logfilename.c_str(), fh = os_file_create_func(logfilename.c_str(),
OS_FILE_OPEN_RETRY | OS_FILE_ON_ERROR_NO_EXIT OS_FILE_OPEN_RETRY_SILENT,
| OS_FILE_ON_ERROR_SILENT,
OS_FILE_NORMAL, OS_LOG_FILE, OS_FILE_NORMAL, OS_LOG_FILE,
srv_read_only_mode, &ret); srv_read_only_mode, &ret);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment