Commit 1e794e4d authored by Zardosht Kasheff's avatar Zardosht Kasheff Committed by Yoni Fogel

addresses #1032

put locks around pread

git-svn-id: file:///svn/toku/tokudb.1032b@8179 c7de825b-a66e-492c-adef-691d508d4ae1
parent 81ffdf96
...@@ -359,7 +359,9 @@ int toku_deserialize_brtnode_from (int fd, BLOCKNUM blocknum, u_int32_t fullhash ...@@ -359,7 +359,9 @@ int toku_deserialize_brtnode_from (int fd, BLOCKNUM blocknum, u_int32_t fullhash
u_int32_t uncompressed_size; u_int32_t uncompressed_size;
{ {
// get the compressed size // get the compressed size
lock_for_pwrite();
r = pread(fd, uncompressed_header, sizeof(uncompressed_header), offset); r = pread(fd, uncompressed_header, sizeof(uncompressed_header), offset);
unlock_for_pwrite();
//printf("%s:%d r=%d the datasize=%d\n", __FILE__, __LINE__, r, toku_ntohl(datasize_n)); //printf("%s:%d r=%d the datasize=%d\n", __FILE__, __LINE__, r, toku_ntohl(datasize_n));
if (r!=(int)sizeof(uncompressed_header)) { if (r!=(int)sizeof(uncompressed_header)) {
if (r==-1) r=errno; if (r==-1) r=errno;
...@@ -379,7 +381,9 @@ int toku_deserialize_brtnode_from (int fd, BLOCKNUM blocknum, u_int32_t fullhash ...@@ -379,7 +381,9 @@ int toku_deserialize_brtnode_from (int fd, BLOCKNUM blocknum, u_int32_t fullhash
assert(compressed_data); assert(compressed_data);
{ {
lock_for_pwrite();
ssize_t rlen=pread(fd, compressed_data, compressed_size, offset+uncompressed_magic_len + compression_header_len); ssize_t rlen=pread(fd, compressed_data, compressed_size, offset+uncompressed_magic_len + compression_header_len);
unlock_for_pwrite();
//printf("%s:%d pread->%d offset=%ld datasize=%d\n", __FILE__, __LINE__, r, offset, compressed_size + uncompressed_magic_len + compression_header_len); //printf("%s:%d pread->%d offset=%ld datasize=%d\n", __FILE__, __LINE__, r, offset, compressed_size + uncompressed_magic_len + compression_header_len);
assert((size_t)rlen==compressed_size); assert((size_t)rlen==compressed_size);
//printf("Got %d %d %d %d\n", rc.buf[0], rc.buf[1], rc.buf[2], rc.buf[3]); //printf("Got %d %d %d %d\n", rc.buf[0], rc.buf[1], rc.buf[2], rc.buf[3]);
...@@ -743,7 +747,9 @@ deserialize_brtheader (u_int32_t size, int fd, DISKOFF off, struct brt_header ** ...@@ -743,7 +747,9 @@ deserialize_brtheader (u_int32_t size, int fd, DISKOFF off, struct brt_header **
if (rc.size<=0) { ret = EINVAL; goto died1; } if (rc.size<=0) { ret = EINVAL; goto died1; }
rc.ndone = 0; rc.ndone = 0;
{ {
lock_for_pwrite();
ssize_t r = pread(fd, rc.buf, size-12, off+12); ssize_t r = pread(fd, rc.buf, size-12, off+12);
unlock_for_pwrite();
if (r!=(ssize_t)size-12) { ret = EINVAL; goto died1; } if (r!=(ssize_t)size-12) { ret = EINVAL; goto died1; }
} }
h->dirty=0; h->dirty=0;
...@@ -840,7 +846,9 @@ int toku_deserialize_brtheader_from (int fd, BLOCKNUM blocknum, struct brt_heade ...@@ -840,7 +846,9 @@ int toku_deserialize_brtheader_from (int fd, BLOCKNUM blocknum, struct brt_heade
//printf("%s:%d malloced %p\n", __FILE__, __LINE__, h); //printf("%s:%d malloced %p\n", __FILE__, __LINE__, h);
char magic[12]; char magic[12];
lock_for_pwrite();
ssize_t r = pread(fd, magic, 12, offset); ssize_t r = pread(fd, magic, 12, offset);
unlock_for_pwrite();
if (r==0) return -1; if (r==0) return -1;
if (r<0) return errno; if (r<0) return errno;
if (r!=12) return EINVAL; if (r!=12) return EINVAL;
...@@ -912,7 +920,9 @@ int toku_serialize_fifo_at (int fd, toku_off_t freeoff, FIFO fifo) { ...@@ -912,7 +920,9 @@ int toku_serialize_fifo_at (int fd, toku_off_t freeoff, FIFO fifo) {
static int static int
read_int (int fd, toku_off_t *at, u_int32_t *result) { read_int (int fd, toku_off_t *at, u_int32_t *result) {
int v; int v;
lock_for_pwrite();
ssize_t r = pread(fd, &v, 4, *at); ssize_t r = pread(fd, &v, 4, *at);
unlock_for_pwrite();
if (r<0) return errno; if (r<0) return errno;
assert(r==4); assert(r==4);
*result = toku_ntohl(v); *result = toku_ntohl(v);
...@@ -922,7 +932,9 @@ read_int (int fd, toku_off_t *at, u_int32_t *result) { ...@@ -922,7 +932,9 @@ read_int (int fd, toku_off_t *at, u_int32_t *result) {
static int static int
read_char (int fd, toku_off_t *at, char *result) { read_char (int fd, toku_off_t *at, char *result) {
lock_for_pwrite();
ssize_t r = pread(fd, result, 1, *at); ssize_t r = pread(fd, result, 1, *at);
unlock_for_pwrite();
if (r<0) return errno; if (r<0) return errno;
assert(r==1); assert(r==1);
(*at)++; (*at)++;
...@@ -943,7 +955,9 @@ static int ...@@ -943,7 +955,9 @@ static int
read_nbytes (int fd, toku_off_t *at, char **data, u_int32_t len) { read_nbytes (int fd, toku_off_t *at, char **data, u_int32_t len) {
char *result = toku_malloc(len); char *result = toku_malloc(len);
if (result==0) return errno; if (result==0) return errno;
lock_for_pwrite();
ssize_t r = pread(fd, result, len, *at); ssize_t r = pread(fd, result, len, *at);
unlock_for_pwrite();
//printf("%s:%d read %d bytes at %" PRId64 ", which are %s\n", __FILE__, __LINE__, len, *at, result); //printf("%s:%d read %d bytes at %" PRId64 ", which are %s\n", __FILE__, __LINE__, len, *at, result);
if (r<0) return errno; if (r<0) return errno;
assert(r==(ssize_t)len); assert(r==(ssize_t)len);
......
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