summaryrefslogtreecommitdiff
path: root/innobase
diff options
context:
space:
mode:
authorunknown <heikki@hundin.mysql.fi>2004-06-03 17:02:37 +0300
committerunknown <heikki@hundin.mysql.fi>2004-06-03 17:02:37 +0300
commitbdabdb766e150e7abe4e69ced5cc2fd4152cef95 (patch)
treec49ae981e47b6bba67b478bef11dcffadf402075 /innobase
parent3b2201c837ec2c329dc905b7da3e4f06c926afe6 (diff)
downloadmariadb-git-bdabdb766e150e7abe4e69ced5cc2fd4152cef95.tar.gz
os0file.c, fil0fil.c:
Align file i/o buffers for DIRECT_IO; fix mem_alloc()/mem_free() crash bugs that came from Marko's latest cleanup innobase/fil/fil0fil.c: Align file i/o buffers for DIRECT_IO; fix mem_alloc()/mem_free() crash bugs that came from Marko's latest cleanup innobase/os/os0file.c: Align file i/o buffers for DIRECT_IO; fix mem_alloc()/mem_free() crash bugs that came from Marko's latest cleanup
Diffstat (limited to 'innobase')
-rw-r--r--innobase/fil/fil0fil.c67
-rw-r--r--innobase/os/os0file.c22
2 files changed, 54 insertions, 35 deletions
diff --git a/innobase/fil/fil0fil.c b/innobase/fil/fil0fil.c
index 38d06c5bfba..e1e19ec467c 100644
--- a/innobase/fil/fil0fil.c
+++ b/innobase/fil/fil0fil.c
@@ -1409,6 +1409,7 @@ fil_read_flushed_lsn_and_arch_log_no(
byte* buf;
byte* buf2;
dulint flushed_lsn;
+
buf2 = ut_malloc(2 * UNIV_PAGE_SIZE);
/* Align the memory for a possible read from a raw device */
buf = ut_align(buf2, UNIV_PAGE_SIZE);
@@ -1852,8 +1853,6 @@ try_again:
success = os_file_delete(path);
}
- mem_free(path);
-
if (success) {
#ifndef UNIV_HOTBACKUP
/* Write a log record about the deletion of the .ibd
@@ -1869,9 +1868,13 @@ try_again:
fil_op_write_log(MLOG_FILE_DELETE, id, path, NULL, &mtr);
mtr_commit(&mtr);
#endif
+ mem_free(path);
+
return(TRUE);
}
+ mem_free(path);
+
return(FALSE);
}
@@ -2148,6 +2151,7 @@ fil_create_new_single_table_tablespace(
os_file_t file;
ibool ret;
ulint err;
+ byte* buf2;
byte* page;
ibool success;
char* path;
@@ -2191,12 +2195,14 @@ fil_create_new_single_table_tablespace(
return(DB_ERROR);
}
- page = ut_malloc(UNIV_PAGE_SIZE);
+ buf2 = ut_malloc(2 * UNIV_PAGE_SIZE);
+ /* Align the memory for file i/o if we might have O_DIRECT set */
+ page = ut_align(buf2, UNIV_PAGE_SIZE);
ret = os_file_set_size(path, file, size * UNIV_PAGE_SIZE, 0);
if (!ret) {
- ut_free(page);
+ ut_free(buf2);
os_file_close(file);
os_file_delete(path);
@@ -2211,7 +2217,7 @@ fil_create_new_single_table_tablespace(
/* printf("Creating tablespace %s id %lu\n", path, *space_id); */
if (*space_id == ULINT_UNDEFINED) {
- ut_free(page);
+ ut_free(buf2);
error_exit:
os_file_close(file);
os_file_delete(path);
@@ -2237,7 +2243,7 @@ fil_create_new_single_table_tablespace(
ret = os_file_write(path, file, page, 0, 0, UNIV_PAGE_SIZE);
- ut_free(page);
+ ut_free(buf2);
if (!ret) {
fprintf(stderr,
@@ -2308,6 +2314,7 @@ fil_reset_too_high_lsns(
os_file_t file;
char* filepath;
byte* page;
+ byte* buf2;
dulint flush_lsn;
ulint space_id;
ib_longlong file_size;
@@ -2320,14 +2327,16 @@ fil_reset_too_high_lsns(
file = os_file_create_simple_no_error_handling(filepath, OS_FILE_OPEN,
OS_FILE_READ_WRITE, &success);
if (!success) {
- ut_free(filepath);
+ mem_free(filepath);
return(FALSE);
}
/* Read the first page of the tablespace */
- page = ut_malloc(UNIV_PAGE_SIZE);
+ buf2 = ut_malloc(2 * UNIV_PAGE_SIZE);
+ /* Align the memory for file i/o if we might have O_DIRECT set */
+ page = ut_align(buf2, UNIV_PAGE_SIZE);
success = os_file_read(file, page, 0, 0, UNIV_PAGE_SIZE);
if (!success) {
@@ -2414,8 +2423,8 @@ fil_reset_too_high_lsns(
success = os_file_flush(file);
func_exit:
os_file_close(file);
- ut_free(page);
- ut_free(filepath);
+ ut_free(buf2);
+ mem_free(filepath);
return(success);
}
@@ -2440,6 +2449,7 @@ fil_open_single_table_tablespace(
os_file_t file;
char* filepath;
ibool success;
+ byte* buf2;
byte* page;
ulint space_id;
ibool ret = TRUE;
@@ -2463,14 +2473,16 @@ fil_open_single_table_tablespace(
"InnoDB: You can look from section 15.1 of http://www.innodb.com/ibman.html\n"
"InnoDB: how to resolve the issue.\n");
- ut_free(filepath);
+ mem_free(filepath);
return(FALSE);
}
/* Read the first page of the tablespace */
- page = ut_malloc(UNIV_PAGE_SIZE);
+ buf2 = ut_malloc(2 * UNIV_PAGE_SIZE);
+ /* Align the memory for file i/o if we might have O_DIRECT set */
+ page = ut_align(buf2, UNIV_PAGE_SIZE);
success = os_file_read(file, page, 0, 0, UNIV_PAGE_SIZE);
@@ -2507,8 +2519,8 @@ fil_open_single_table_tablespace(
fil_node_create(filepath, 0, space_id, FALSE);
func_exit:
os_file_close(file);
- ut_free(page);
- ut_free(filepath);
+ ut_free(buf2);
+ mem_free(filepath);
return(ret);
}
@@ -2516,7 +2528,7 @@ func_exit:
#ifdef UNIV_HOTBACKUP
/***********************************************************************
Allocates a file name for an old version of a single-table tablespace.
-The string must be freed by caller with mem_free(). */
+The string must be freed by caller with ut_free(), NOT with mem_free()! */
static
char*
fil_make_ibbackup_old_name(
@@ -2549,6 +2561,7 @@ fil_load_single_table_tablespace(
os_file_t file;
char* filepath;
ibool success;
+ byte* buf2;
byte* page;
ulint space_id;
ulint size_low;
@@ -2655,7 +2668,9 @@ fil_load_single_table_tablespace(
#endif
/* Read the first page of the tablespace if the size big enough */
- page = ut_malloc(UNIV_PAGE_SIZE);
+ buf2 = ut_malloc(2 * UNIV_PAGE_SIZE);
+ /* Align the memory for file i/o if we might have O_DIRECT set */
+ page = ut_align(buf2, UNIV_PAGE_SIZE);
if (size >= FIL_IBD_FILE_INITIAL_SIZE * UNIV_PAGE_SIZE) {
success = os_file_read(file, page, 0, 0, UNIV_PAGE_SIZE);
@@ -2691,7 +2706,7 @@ fil_load_single_table_tablespace(
new_path = fil_make_ibbackup_old_name(filepath);
ut_a(os_file_rename(filepath, new_path));
- ut_free(page);
+ ut_free(buf2);
ut_free(filepath);
ut_free(new_path);
@@ -2727,7 +2742,7 @@ fil_load_single_table_tablespace(
ut_a(os_file_rename(filepath, new_path));
- ut_free(page);
+ ut_free(buf2);
ut_free(filepath);
ut_free(new_path);
@@ -2748,7 +2763,7 @@ fil_load_single_table_tablespace(
fil_node_create(filepath, 0, space_id, FALSE);
func_exit:
os_file_close(file);
- ut_free(page);
+ ut_free(buf2);
ut_free(filepath);
}
@@ -2767,7 +2782,7 @@ fil_load_single_table_tablespaces(void)
{
int ret;
char* dbpath = NULL;
- ulint dbpath_len = 0;
+ ulint dbpath_len = 100;
os_file_dir_t dir;
os_file_dir_t dbdir;
os_file_stat_t dbinfo;
@@ -2782,7 +2797,7 @@ fil_load_single_table_tablespaces(void)
return(DB_ERROR);
}
- dbpath = ut_malloc(dbpath_len);
+ dbpath = mem_alloc(dbpath_len);
/* Scan all directories under the datadir. They are the database
directories of MySQL. */
@@ -2806,10 +2821,10 @@ fil_load_single_table_tablespaces(void)
+ strlen (dbinfo.name) + 2;
if (len > dbpath_len) {
dbpath_len = len;
+
if (!dbpath) {
dbpath = mem_alloc(dbpath_len);
- }
- else {
+ } else {
dbpath = mem_realloc(dbpath, dbpath_len,
__FILE__, __LINE__);
}
@@ -2863,9 +2878,7 @@ next_datadir_item:
dir, &dbinfo);
}
- if (dbpath) {
- ut_free(dbpath);
- }
+ mem_free(dbpath);
/* At the end of directory we should get 1 as the return value, -1
if there was an error */
@@ -3280,7 +3293,7 @@ fil_extend_space_to_desired_size(
/************************************************************************
Extends all tablespaces to the size stored in the space header. During the
ibbackup --apply-log phase we extended the spaces on-demand so that log records
-could be appllied, but that may have left spaces still too small compared to
+could be applied, but that may have left spaces still too small compared to
the size stored in the space header. */
void
diff --git a/innobase/os/os0file.c b/innobase/os/os0file.c
index fafed2a484c..57e9690d990 100644
--- a/innobase/os/os0file.c
+++ b/innobase/os/os0file.c
@@ -2341,21 +2341,24 @@ os_file_dirname(
pathname */
const char* path) /* in: pathname */
{
- /* find the offset of the last slash */
+ /* Find the offset of the last slash */
const char* last_slash = strrchr(path, OS_FILE_PATH_SEPARATOR);
if (!last_slash) {
- /* no slash in the path, return "." */
+ /* No slash in the path, return "." */
+
return(mem_strdup("."));
}
- /* ok, there is a slash */
+ /* Ok, there is a slash */
if (last_slash == path) {
/* last slash is the first char of the path */
+
return(mem_strdup("/"));
}
- /* non-trivial directory component */
+ /* Non-trivial directory component */
+
return(mem_strdupl(path, last_slash - path));
}
@@ -2377,23 +2380,26 @@ os_file_create_subdirs_if_needed(
if (strlen(subdir) == 1
&& (*subdir == OS_FILE_PATH_SEPARATOR || *subdir == '.')) {
/* subdir is root or cwd, nothing to do */
- ut_free(subdir);
+ mem_free(subdir);
+
return(TRUE);
}
- /* test if subdir exists */
+ /* Test if subdir exists */
success = os_file_status(subdir, &subdir_exists, &type);
if (success && !subdir_exists) {
/* subdir does not exist, create it */
success = os_file_create_subdirs_if_needed(subdir);
if (!success) {
- ut_free(subdir);
+ mem_free(subdir);
+
return(FALSE);
}
success = os_file_create_directory(subdir, FALSE);
}
- ut_free(subdir);
+ mem_free(subdir);
+
return(success);
}