Commit 061de97e authored by Barry Perlman's avatar Barry Perlman Committed by Yoni Fogel

Closes [t:2612] Make separate override functions for use by toku_os_write(),...

Closes [t:2612] Make separate override functions for use by toku_os_write(), toku_os_full_write(), toku_os_pwrite(), and toku_os_full_pwrite(). Modify src/tests/diskfull.c to use new override functions.

git-svn-id: file:///svn/toku/tokudb@20220 c7de825b-a66e-492c-adef-691d508d4ae1
parent 3bd180d1
......@@ -485,7 +485,9 @@ int toku_close_trace_file (void) __attribute__((__visibility__("default")));
int db_env_set_func_free (void (*)(void*)) __attribute__((__visibility__("default")));
int db_env_set_func_malloc (void *(*)(size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) __attribute__((__visibility__("default")));
int db_env_set_func_full_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) __attribute__((__visibility__("default")));
int db_env_set_func_write (ssize_t (*)(int, const void *, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_full_write (ssize_t (*)(int, const void *, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_realloc (void *(*)(void*, size_t)) __attribute__((__visibility__("default")));
void db_env_set_func_loader_fwrite (size_t (*fwrite_fun)(const void*,size_t,size_t,FILE*)) __attribute__((__visibility__("default")));
void db_env_set_checkpoint_callback (void (*)(void*), void*) __attribute__((__visibility__("default")));
......
......@@ -501,7 +501,9 @@ int toku_close_trace_file (void) __attribute__((__visibility__("default")));
int db_env_set_func_free (void (*)(void*)) __attribute__((__visibility__("default")));
int db_env_set_func_malloc (void *(*)(size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) __attribute__((__visibility__("default")));
int db_env_set_func_full_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) __attribute__((__visibility__("default")));
int db_env_set_func_write (ssize_t (*)(int, const void *, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_full_write (ssize_t (*)(int, const void *, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_realloc (void *(*)(void*, size_t)) __attribute__((__visibility__("default")));
void db_env_set_func_loader_fwrite (size_t (*fwrite_fun)(const void*,size_t,size_t,FILE*)) __attribute__((__visibility__("default")));
void db_env_set_checkpoint_callback (void (*)(void*), void*) __attribute__((__visibility__("default")));
......
......@@ -509,7 +509,9 @@ int toku_close_trace_file (void) __attribute__((__visibility__("default")));
int db_env_set_func_free (void (*)(void*)) __attribute__((__visibility__("default")));
int db_env_set_func_malloc (void *(*)(size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) __attribute__((__visibility__("default")));
int db_env_set_func_full_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) __attribute__((__visibility__("default")));
int db_env_set_func_write (ssize_t (*)(int, const void *, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_full_write (ssize_t (*)(int, const void *, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_realloc (void *(*)(void*, size_t)) __attribute__((__visibility__("default")));
void db_env_set_func_loader_fwrite (size_t (*fwrite_fun)(const void*,size_t,size_t,FILE*)) __attribute__((__visibility__("default")));
void db_env_set_checkpoint_callback (void (*)(void*), void*) __attribute__((__visibility__("default")));
......
......@@ -509,7 +509,9 @@ int toku_close_trace_file (void) __attribute__((__visibility__("default")));
int db_env_set_func_free (void (*)(void*)) __attribute__((__visibility__("default")));
int db_env_set_func_malloc (void *(*)(size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) __attribute__((__visibility__("default")));
int db_env_set_func_full_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) __attribute__((__visibility__("default")));
int db_env_set_func_write (ssize_t (*)(int, const void *, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_full_write (ssize_t (*)(int, const void *, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_realloc (void *(*)(void*, size_t)) __attribute__((__visibility__("default")));
void db_env_set_func_loader_fwrite (size_t (*fwrite_fun)(const void*,size_t,size_t,FILE*)) __attribute__((__visibility__("default")));
void db_env_set_checkpoint_callback (void (*)(void*), void*) __attribute__((__visibility__("default")));
......
......@@ -514,7 +514,9 @@ int toku_close_trace_file (void) __attribute__((__visibility__("default")));
int db_env_set_func_free (void (*)(void*)) __attribute__((__visibility__("default")));
int db_env_set_func_malloc (void *(*)(size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) __attribute__((__visibility__("default")));
int db_env_set_func_full_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) __attribute__((__visibility__("default")));
int db_env_set_func_write (ssize_t (*)(int, const void *, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_full_write (ssize_t (*)(int, const void *, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_realloc (void *(*)(void*, size_t)) __attribute__((__visibility__("default")));
void db_env_set_func_loader_fwrite (size_t (*fwrite_fun)(const void*,size_t,size_t,FILE*)) __attribute__((__visibility__("default")));
void db_env_set_checkpoint_callback (void (*)(void*), void*) __attribute__((__visibility__("default")));
......
......@@ -670,7 +670,9 @@ int main (int argc __attribute__((__unused__)), char *const argv[] __attribute__
printf("int db_env_set_func_free (void (*)(void*)) %s;\n", VISIBLE);
printf("int db_env_set_func_malloc (void *(*)(size_t)) %s;\n", VISIBLE);
printf("int db_env_set_func_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) %s;\n", VISIBLE);
printf("int db_env_set_func_full_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) %s;\n", VISIBLE);
printf("int db_env_set_func_write (ssize_t (*)(int, const void *, size_t)) %s;\n", VISIBLE);
printf("int db_env_set_func_full_write (ssize_t (*)(int, const void *, size_t)) %s;\n", VISIBLE);
printf("int db_env_set_func_realloc (void *(*)(void*, size_t)) %s;\n", VISIBLE);
printf("void db_env_set_func_loader_fwrite (size_t (*fwrite_fun)(const void*,size_t,size_t,FILE*)) %s;\n", VISIBLE);
printf("void db_env_set_checkpoint_callback (void (*)(void*), void*) %s;\n", VISIBLE);
......
......@@ -446,7 +446,9 @@ int toku_close_trace_file (void) __attribute__((__visibility__("default")));
int db_env_set_func_free (void (*)(void*)) __attribute__((__visibility__("default")));
int db_env_set_func_malloc (void *(*)(size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) __attribute__((__visibility__("default")));
int db_env_set_func_full_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) __attribute__((__visibility__("default")));
int db_env_set_func_write (ssize_t (*)(int, const void *, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_full_write (ssize_t (*)(int, const void *, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_realloc (void *(*)(void*, size_t)) __attribute__((__visibility__("default")));
void db_env_set_func_loader_fwrite (size_t (*fwrite_fun)(const void*,size_t,size_t,FILE*)) __attribute__((__visibility__("default")));
void db_env_set_checkpoint_callback (void (*)(void*), void*) __attribute__((__visibility__("default")));
......
......@@ -446,7 +446,9 @@ int toku_close_trace_file (void) __attribute__((__visibility__("default")));
int db_env_set_func_free (void (*)(void*)) __attribute__((__visibility__("default")));
int db_env_set_func_malloc (void *(*)(size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) __attribute__((__visibility__("default")));
int db_env_set_func_full_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t)) __attribute__((__visibility__("default")));
int db_env_set_func_write (ssize_t (*)(int, const void *, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_full_write (ssize_t (*)(int, const void *, size_t)) __attribute__((__visibility__("default")));
int db_env_set_func_realloc (void *(*)(void*, size_t)) __attribute__((__visibility__("default")));
void db_env_set_func_loader_fwrite (size_t (*fwrite_fun)(const void*,size_t,size_t,FILE*)) __attribute__((__visibility__("default")));
void db_env_set_checkpoint_callback (void (*)(void*), void*) __attribute__((__visibility__("default")));
......
......@@ -94,7 +94,25 @@ try_again_after_handling_write_error(int fd, size_t len, ssize_t r_write) {
errno = errno_write;
}
static ssize_t (*t_write)(int, const void *, size_t) = 0;
static ssize_t (*t_full_write)(int, const void *, size_t) = 0;
static ssize_t (*t_pwrite)(int, const void *, size_t, off_t) = 0;
static ssize_t (*t_full_pwrite)(int, const void *, size_t, off_t) = 0;
int
toku_set_func_write (ssize_t (*write_fun)(int, const void *, size_t)) {
t_write = write_fun;
return 0;
}
int
toku_set_func_full_write (ssize_t (*write_fun)(int, const void *, size_t)) {
t_full_write = write_fun;
return 0;
}
int
toku_set_func_pwrite (ssize_t (*pwrite_fun)(int, const void *, size_t, off_t)) {
......@@ -102,20 +120,27 @@ toku_set_func_pwrite (ssize_t (*pwrite_fun)(int, const void *, size_t, off_t)) {
return 0;
}
int
toku_set_func_full_pwrite (ssize_t (*pwrite_fun)(int, const void *, size_t, off_t)) {
t_full_pwrite = pwrite_fun;
return 0;
}
void
toku_os_full_pwrite (int fd, const void *buf, size_t len, toku_off_t off) {
toku_os_full_write (int fd, const void *buf, size_t len) {
const char *bp = (const char *) buf;
while (len > 0) {
ssize_t r;
if (t_pwrite) {
r = t_pwrite(fd, bp, len, off);
if (t_full_write) {
r = t_full_write(fd, bp, len);
} else {
r = pwrite(fd, bp, len, off);
r = write(fd, bp, len);
}
if (r > 0) {
len -= r;
bp += r;
off += r;
}
else {
try_again_after_handling_write_error(fd, len, r);
......@@ -125,15 +150,15 @@ toku_os_full_pwrite (int fd, const void *buf, size_t len, toku_off_t off) {
}
int
toku_os_pwrite (int fd, const void *buf, size_t len, toku_off_t off) {
toku_os_write (int fd, const void *buf, size_t len) {
const char *bp = (const char *) buf;
int result = 0;
while (len > 0) {
ssize_t r;
if (t_pwrite) {
r = t_pwrite(fd, bp, len, off);
if (t_write) {
r = t_write(fd, bp, len);
} else {
r = pwrite(fd, bp, len, off);
r = write(fd, bp, len);
}
if (r < 0) {
result = errno;
......@@ -141,32 +166,24 @@ toku_os_pwrite (int fd, const void *buf, size_t len, toku_off_t off) {
}
len -= r;
bp += r;
off += r;
}
return result;
}
static ssize_t (*t_write)(int, const void *, size_t) = 0;
int
toku_set_func_write (ssize_t (*write_fun)(int, const void *, size_t)) {
t_write = write_fun;
return 0;
}
void
toku_os_full_write (int fd, const void *buf, size_t len) {
toku_os_full_pwrite (int fd, const void *buf, size_t len, toku_off_t off) {
const char *bp = (const char *) buf;
while (len > 0) {
ssize_t r;
if (t_write) {
r = t_write(fd, bp, len);
if (t_full_pwrite) {
r = t_full_pwrite(fd, bp, len, off);
} else {
r = write(fd, bp, len);
r = pwrite(fd, bp, len, off);
}
if (r > 0) {
len -= r;
bp += r;
off += r;
}
else {
try_again_after_handling_write_error(fd, len, r);
......@@ -176,15 +193,15 @@ toku_os_full_write (int fd, const void *buf, size_t len) {
}
int
toku_os_write (int fd, const void *buf, size_t len) {
toku_os_pwrite (int fd, const void *buf, size_t len, toku_off_t off) {
const char *bp = (const char *) buf;
int result = 0;
while (len > 0) {
ssize_t r;
if (t_write) {
r = t_write(fd, bp, len);
if (t_pwrite) {
r = t_pwrite(fd, bp, len, off);
} else {
r = write(fd, bp, len);
r = pwrite(fd, bp, len, off);
}
if (r < 0) {
result = errno;
......@@ -192,10 +209,13 @@ toku_os_write (int fd, const void *buf, size_t len) {
}
len -= r;
bp += r;
off += r;
}
return result;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// fsync logic:
......
......@@ -10,7 +10,9 @@
db_env_set_func_realloc;
db_env_set_func_free;
db_env_set_func_pwrite;
db_env_set_func_full_pwrite;
db_env_set_func_write;
db_env_set_func_full_write;
db_env_set_func_loader_fwrite;
db_env_set_checkpoint_callback;
db_env_set_checkpoint_callback2;
......
......@@ -167,7 +167,9 @@ do_writes_that_fail (void) {
if (verbose) { printf("About to fail at %d:\n", fail_at); fflush(stdout); }
toku_set_assert_on_write_enospc(TRUE);
db_env_set_func_pwrite(pwrite_counting_and_failing);
db_env_set_func_full_pwrite(pwrite_counting_and_failing);
db_env_set_func_write (write_counting_and_failing);
db_env_set_func_full_write (write_counting_and_failing);
write_count=0;
do_db_work();
printf("%d", write_count);
......
......@@ -5617,9 +5617,15 @@ int db_env_set_func_fsync (int (*fsync_function)(int)) {
int db_env_set_func_pwrite (ssize_t (*pwrite_function)(int, const void *, size_t, toku_off_t)) {
return toku_set_func_pwrite(pwrite_function);
}
int db_env_set_func_full_pwrite (ssize_t (*pwrite_function)(int, const void *, size_t, toku_off_t)) {
return toku_set_func_full_pwrite(pwrite_function);
}
int db_env_set_func_write (ssize_t (*write_function)(int, const void *, size_t)) {
return toku_set_func_write(write_function);
}
int db_env_set_func_full_write (ssize_t (*write_function)(int, const void *, size_t)) {
return toku_set_func_full_write(write_function);
}
void
db_env_set_func_loader_fwrite (size_t (*fwrite_fun)(const void*,size_t,size_t,FILE*)) {
......
......@@ -173,7 +173,9 @@ int toku_set_func_malloc (void *(*)(size_t));
int toku_set_func_realloc (void *(*)(void*,size_t));
int toku_set_func_free (void (*)(void*));
int toku_set_func_pwrite (ssize_t (*pwrite_fun)(int, const void *, size_t, toku_off_t));
int toku_set_func_full_pwrite (ssize_t (*pwrite_fun)(int, const void *, size_t, toku_off_t));
int toku_set_func_write (ssize_t (*pwrite_fun)(int, const void *, size_t));
int toku_set_func_full_write (ssize_t (*pwrite_fun)(int, const void *, size_t));
int toku_portability_init (void);
int toku_portability_destroy (void);
......
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