diff options
Diffstat (limited to 'innobase/os/os0file.c')
-rw-r--r-- | innobase/os/os0file.c | 208 |
1 files changed, 118 insertions, 90 deletions
diff --git a/innobase/os/os0file.c b/innobase/os/os0file.c index 3f14a2158ed..5f5060c7464 100644 --- a/innobase/os/os0file.c +++ b/innobase/os/os0file.c @@ -70,7 +70,7 @@ struct os_aio_slot_struct{ bytes */ ulint offset_high; /* 32 high bits of file offset */ os_file_t file; /* file where to read or write */ - char* name; /* file name or path */ + const char* name; /* file name or path */ ibool io_already_done;/* used only in simulated aio: TRUE if the physical i/o already made and only the slot message @@ -369,7 +369,16 @@ os_file_handle_error( return(FALSE); } -#if !defined(__WIN__) && !defined(UNIV_HOTBACKUP) +#undef USE_FILE_LOCK +#define USE_FILE_LOCK +#if defined(UNIV_HOTBACKUP) || defined(__WIN__) || defined(__FreeBSD__) +/* InnoDB Hot Backup does not lock the data files. + * On Windows, mandatory locking is used. + * On FreeBSD with LinuxThreads, advisory locking does not work properly. + */ +# undef USE_FILE_LOCK +#endif +#ifdef USE_FILE_LOCK /******************************************************************** Obtain an exclusive lock on a file. */ static @@ -378,22 +387,24 @@ os_file_lock( /*=========*/ /* out: 0 on success */ int fd, /* in: file descriptor */ - const char* name) /* in: file name */ + const char* name, /* in: file name */ + uint lock_type) /* in: lock_type */ { struct flock lk; - lk.l_type = F_WRLCK; + lk.l_type = lock_type; lk.l_whence = SEEK_SET; lk.l_start = lk.l_len = 0; if (fcntl(fd, F_SETLK, &lk) == -1) { fprintf(stderr, - "InnoDB: Unable to lock %s", name); + "InnoDB: Unable to lock %s with lock %d, error: %d", + name, lock_type, errno); perror (": fcntl"); close(fd); return(-1); } return 0; } -#endif /* !defined(__WIN__) && !defined(UNIV_HOTBACKUP) */ +#endif /* USE_FILE_LOCK */ /******************************************************************** Does error handling when a file operation fails. */ @@ -404,7 +415,7 @@ os_file_handle_error_no_exit( /* out: TRUE if we should retry the operation */ os_file_t file, /* in: file pointer */ - char* name, /* in: name of a file or NULL */ + const char* name, /* in: name of a file or NULL */ const char* operation)/* in: operation */ { ulint err; @@ -482,13 +493,15 @@ and '..' items at the start of the directory listing. */ os_file_dir_t os_file_opendir( /*============*/ - /* out: directory stream, NULL if error */ - char* dirname, /* in: directory name; it must not contain - a trailing '\' or '/' */ - ibool error_is_fatal) /* in: TRUE if we should treat an error as a - fatal error; if we try to open symlinks then - we do not wish a fatal error if it happens - not to be a directory */ + /* out: directory stream, NULL if + error */ + const char* dirname, /* in: directory name; it must not + contain a trailing '\' or '/' */ + ibool error_is_fatal) /* in: TRUE if we should treat an + error as a fatal error; if we try to + open symlinks then we do not wish a + fatal error if it happens not to be + a directory */ { os_file_dir_t dir; #ifdef __WIN__ @@ -574,7 +587,7 @@ os_file_readdir_next_file( /*======================*/ /* out: 0 if ok, -1 if error, 1 if at the end of the directory */ - char* dirname,/* in: directory name or path */ + const char* dirname,/* in: directory name or path */ os_file_dir_t dir, /* in: directory stream */ os_file_stat_t* info) /* in/out: buffer where the info is returned */ { @@ -693,12 +706,12 @@ fail_if_exists arguments is true. */ ibool os_file_create_directory( /*=====================*/ - /* out: TRUE if call succeeds, FALSE on - error */ - char* pathname, /* in: directory name as null-terminated - string */ - ibool fail_if_exists) /* in: if TRUE, pre-existing directory is - treated as an error. */ + /* out: TRUE if call succeeds, + FALSE on error */ + const char* pathname, /* in: directory name as + null-terminated string */ + ibool fail_if_exists) /* in: if TRUE, pre-existing directory + is treated as an error. */ { #ifdef __WIN__ BOOL rcode; @@ -735,18 +748,21 @@ A simple function to open or create a file. */ os_file_t os_file_create_simple( /*==================*/ - /* out, own: handle to the file, not defined if error, - error number can be retrieved with - os_file_get_last_error */ - char* name, /* in: name of the file or path as a null-terminated - string */ - ulint create_mode,/* in: OS_FILE_OPEN if an existing file is opened - (if does not exist, error), or OS_FILE_CREATE if a new - file is created (if exists, error), or - OS_FILE_CREATE_PATH if new file (if exists, error) and - subdirectories along its path are created (if needed)*/ - ulint access_type,/* in: OS_FILE_READ_ONLY or OS_FILE_READ_WRITE */ - ibool* success)/* out: TRUE if succeed, FALSE if error */ + /* out, own: handle to the file, not defined + if error, error number can be retrieved with + os_file_get_last_error */ + const char* name, /* in: name of the file or path as a + null-terminated string */ + ulint create_mode,/* in: OS_FILE_OPEN if an existing file is + opened (if does not exist, error), or + OS_FILE_CREATE if a new file is created + (if exists, error), or + OS_FILE_CREATE_PATH if new file + (if exists, error) and subdirectories along + its path are created (if needed)*/ + ulint access_type,/* in: OS_FILE_READ_ONLY or + OS_FILE_READ_WRITE */ + ibool* success)/* out: TRUE if succeed, FALSE if error */ { #ifdef __WIN__ os_file_t file; @@ -852,8 +868,8 @@ try_again: if (retry) { goto try_again; } -#ifndef UNIV_HOTBACKUP - } else if (os_file_lock(file, name)) { +#ifdef USE_FILE_LOCK + } else if (os_file_lock(file, name, F_WRLCK)) { *success = FALSE; file = -1; #endif @@ -871,18 +887,20 @@ A simple function to open or create a file. */ os_file_t os_file_create_simple_no_error_handling( /*====================================*/ - /* out, own: handle to the file, not defined if error, - error number can be retrieved with - os_file_get_last_error */ - char* name, /* in: name of the file or path as a null-terminated - string */ - ulint create_mode,/* in: OS_FILE_OPEN if an existing file is opened - (if does not exist, error), or OS_FILE_CREATE if a new - file is created (if exists, error) */ - ulint access_type,/* in: OS_FILE_READ_ONLY, OS_FILE_READ_WRITE, or - OS_FILE_READ_ALLOW_DELETE; the last option is used by - a backup program reading the file */ - ibool* success)/* out: TRUE if succeed, FALSE if error */ + /* out, own: handle to the file, not defined + if error, error number can be retrieved with + os_file_get_last_error */ + const char* name, /* in: name of the file or path as a + null-terminated string */ + ulint create_mode,/* in: OS_FILE_OPEN if an existing file + is opened (if does not exist, error), or + OS_FILE_CREATE if a new file is created + (if exists, error) */ + ulint access_type,/* in: OS_FILE_READ_ONLY, + OS_FILE_READ_WRITE, or + OS_FILE_READ_ALLOW_DELETE; the last option is + used by a backup program reading the file */ + ibool* success)/* out: TRUE if succeed, FALSE if error */ { #ifdef __WIN__ os_file_t file; @@ -961,8 +979,8 @@ os_file_create_simple_no_error_handling( if (file == -1) { *success = FALSE; -#ifndef UNIV_HOTBACKUP - } else if (os_file_lock(file, name)) { +#ifdef USE_FILE_LOCK + } else if (os_file_lock(file, name, F_WRLCK)) { *success = FALSE; file = -1; #endif @@ -980,25 +998,28 @@ Opens an existing file or creates a new. */ os_file_t os_file_create( /*===========*/ - /* out, own: handle to the file, not defined if error, - error number can be retrieved with - os_file_get_last_error */ - char* name, /* in: name of the file or path as a null-terminated - string */ - ulint create_mode, /* in: OS_FILE_OPEN if an existing file is opened - (if does not exist, error), or OS_FILE_CREATE if a new - file is created (if exists, error), OS_FILE_OVERWRITE - if a new is created or an old overwritten, - OS_FILE_OPEN_RAW, if a raw device or disk partition - should be opened */ - ulint purpose,/* in: OS_FILE_AIO, if asynchronous, non-buffered i/o - is desired, OS_FILE_NORMAL, if any normal file; - NOTE that it also depends on type, os_aio_.. and srv_.. - variables whether we really use async i/o or - unbuffered i/o: look in the function source code for - the exact rules */ - ulint type, /* in: OS_DATA_FILE or OS_LOG_FILE */ - ibool* success)/* out: TRUE if succeed, FALSE if error */ + /* out, own: handle to the file, not defined + if error, error number can be retrieved with + os_file_get_last_error */ + const char* name, /* in: name of the file or path as a + null-terminated string */ + ulint create_mode,/* in: OS_FILE_OPEN if an existing file + is opened (if does not exist, error), or + OS_FILE_CREATE if a new file is created + (if exists, error), + OS_FILE_OVERWRITE if a new file is created + or an old overwritten; + OS_FILE_OPEN_RAW, if a raw device or disk + partition should be opened */ + ulint purpose,/* in: OS_FILE_AIO, if asynchronous, + non-buffered i/o is desired, + OS_FILE_NORMAL, if any normal file; + NOTE that it also depends on type, os_aio_.. + and srv_.. variables whether we really use + async i/o or unbuffered i/o: look in the + function source code for the exact rules */ + ulint type, /* in: OS_DATA_FILE or OS_LOG_FILE */ + ibool* success)/* out: TRUE if succeed, FALSE if error */ { #ifdef __WIN__ os_file_t file; @@ -1172,8 +1193,8 @@ try_again: if (retry) { goto try_again; } -#ifndef UNIV_HOTBACKUP - } else if (os_file_lock(file, name)) { +#ifdef USE_FILE_LOCK + } else if (os_file_lock(file, name, F_WRLCK)) { *success = FALSE; file = -1; #endif @@ -1191,8 +1212,8 @@ Deletes a file if it exists. The file has to be closed before calling this. */ ibool os_file_delete_if_exists( /*=====================*/ - /* out: TRUE if success */ - char* name) /* in: file path as a null-terminated string */ + /* out: TRUE if success */ + const char* name) /* in: file path as a null-terminated string */ { #ifdef __WIN__ BOOL ret; @@ -1252,8 +1273,8 @@ Deletes a file. The file has to be closed before calling this. */ ibool os_file_delete( /*===========*/ - /* out: TRUE if success */ - char* name) /* in: file path as a null-terminated string */ + /* out: TRUE if success */ + const char* name) /* in: file path as a null-terminated string */ { #ifdef __WIN__ BOOL ret; @@ -1316,9 +1337,9 @@ ibool os_file_rename( /*===========*/ /* out: TRUE if success */ - char* oldpath, /* in: old file path as a null-terminated + const char* oldpath,/* in: old file path as a null-terminated string */ - char* newpath) /* in: new file path */ + const char* newpath)/* in: new file path */ { #ifdef __WIN__ BOOL ret; @@ -1329,7 +1350,7 @@ os_file_rename( return(TRUE); } - os_file_handle_error(NULL, oldpath, "delete"); + os_file_handle_error(NULL, oldpath, "rename"); return(FALSE); #else @@ -1374,6 +1395,9 @@ os_file_close( #else int ret; +#ifdef USE_FILE_LOCK + (void) os_file_lock(file, "unknown", F_UNLCK); +#endif ret = close(file); if (ret == -1) { @@ -1410,6 +1434,9 @@ os_file_close_no_error_handling( #else int ret; +#ifdef USE_FILE_LOCK + (void) os_file_lock(file, "unknown", F_UNLCK); +#endif ret = close(file); if (ret == -1) { @@ -1499,7 +1526,7 @@ ibool os_file_set_size( /*=============*/ /* out: TRUE if success */ - char* name, /* in: name of the file or path as a + const char* name, /* in: name of the file or path as a null-terminated string */ os_file_t file, /* in: handle to a file */ ulint size, /* in: least significant 32 bits of file @@ -1760,7 +1787,7 @@ os_file_pwrite( /*===========*/ /* out: number of bytes written, -1 if error */ os_file_t file, /* in: handle to a file */ - void* buf, /* in: buffer from where to write */ + const void* buf, /* in: buffer from where to write */ ulint n, /* in: number of bytes to write */ ulint offset, /* in: least significant 32 bits of file offset where to write */ @@ -2040,10 +2067,10 @@ os_file_write( /*==========*/ /* out: TRUE if request was successful, FALSE if fail */ - char* name, /* in: name of the file or path as a + const char* name, /* in: name of the file or path as a null-terminated string */ os_file_t file, /* in: handle to a file */ - void* buf, /* in: buffer from which to write */ + const void* buf, /* in: buffer from which to write */ ulint offset, /* in: least significant 32 bits of file offset where to write */ ulint offset_high, /* in: most significant 32 bits of @@ -2197,7 +2224,7 @@ ibool os_file_status( /*===========*/ /* out: TRUE if call succeeded */ - char* path, /* in: pathname of the file */ + const char* path, /* in: pathname of the file */ ibool* exists, /* out: TRUE if file exists */ os_file_type_t* type) /* out: type of the file (if it exists) */ { @@ -2302,7 +2329,7 @@ os_file_dirname( /*============*/ /* out, own: directory component of the pathname */ - char* path) /* in: pathname */ + const char* path) /* in: pathname */ { char* dir; int i, length, last_slash; @@ -2314,18 +2341,18 @@ os_file_dirname( if (last_slash < 0) { /* no slash in the path, return "." */ - return(ut_strdup((char*)".")); + return(mem_strdup(".")); } /* ok, there is a slash */ if (last_slash == 0) { /* last slash is the first char of the path */ - return(ut_strdup((char*)"/")); + return(mem_strdup("/")); } /* non-trivial directory component */ - dir = ut_strdup(path); + dir = mem_strdup(path); dir[last_slash] = 0; return(dir); @@ -2339,7 +2366,7 @@ os_file_create_subdirs_if_needed( /*=============================*/ /* out: TRUE if call succeeded FALSE otherwise */ - char* path) /* in: path name */ + const char* path) /* in: path name */ { char* subdir; static char rootdir[2] = { OS_FILE_PATH_SEPARATOR, 0 }; @@ -2736,7 +2763,7 @@ os_aio_array_reserve_slot( void* message2,/* in: message to be passed along with the aio operation */ os_file_t file, /* in: file handle */ - char* name, /* in: name of the file or path as a + const char* name, /* in: name of the file or path as a null-terminated string */ void* buf, /* in: buffer where to read or from which to write */ @@ -2983,7 +3010,7 @@ os_aio( because i/os are not actually handled until all have been posted: use with great caution! */ - char* name, /* in: name of the file or path as a + const char* name, /* in: name of the file or path as a null-terminated string */ os_file_t file, /* in: handle to a file */ void* buf, /* in: buffer where to read or from which @@ -3526,6 +3553,7 @@ consecutive_loop: if (n_consecutive == 1) { /* We can use the buffer of the i/o request */ combined_buf = slot->buf; + combined_buf2 = NULL; } else { combined_buf2 = ut_malloc(total_len + UNIV_PAGE_SIZE); @@ -3621,7 +3649,7 @@ consecutive_loop: } } - if (n_consecutive > 1) { + if (combined_buf2) { ut_free(combined_buf2); } |