summaryrefslogtreecommitdiffstats
path: root/xlators/storage/bdb/src
diff options
context:
space:
mode:
authorBasavanagowda Kanur <gowda@gluster.com>2009-04-23 04:05:00 +0530
committerAnand V. Avati <avati@amp.gluster.com>2009-04-23 10:43:27 +0530
commitb0acbf09c21ff898ad3315811974e49cc80e6f2b (patch)
treea21fd136b11506bc1b53da6b7a7d41264cc2867f /xlators/storage/bdb/src
parente5686c440f3c03fbb24759342e5badf102579634 (diff)
fix bdb_db_get() to return exactly read bytes and to copy the read data to given buffer only when needed.
Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
Diffstat (limited to 'xlators/storage/bdb/src')
-rw-r--r--xlators/storage/bdb/src/bdb-ll.c26
-rw-r--r--xlators/storage/bdb/src/bdb.c2
2 files changed, 18 insertions, 10 deletions
diff --git a/xlators/storage/bdb/src/bdb-ll.c b/xlators/storage/bdb/src/bdb-ll.c
index 04cdbfbb3cf..777ff63e1a3 100644
--- a/xlators/storage/bdb/src/bdb-ll.c
+++ b/xlators/storage/bdb/src/bdb-ll.c
@@ -529,7 +529,9 @@ bdb_db_get (bctx_t *bctx,
value.flags = DB_DBT_MALLOC;
} else {
if (size) {
- value.flags = DB_DBT_MALLOC | DB_DBT_PARTIAL;
+ value.data = buf;
+ value.ulen = size;
+ value.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
} else {
value.flags = DB_DBT_MALLOC;
}
@@ -560,18 +562,24 @@ bdb_db_get (bctx_t *bctx,
} else if (ret == 0) {
/* successfully read data, lets set everything
* in place and return */
- if (buf) {
- copy_size = ((value.size - offset) < size) ?
- (value.size - offset) : size;
+ if (bctx->cache) {
+ if (buf) {
+ copy_size = ((value.size - offset) < size) ?
+ (value.size - offset) : size;
+
+ memcpy (buf, (value.data + offset),
+ copy_size);
+ ret = copy_size;
+ }
- memcpy (buf, (value.data + offset), copy_size);
- ret = copy_size;
+ bdb_cache_insert (bctx, &key, &value);
} else {
ret = value.size;
}
- if (bctx->cache)
- bdb_cache_insert (bctx, &key, &value);
- free (value.data);
+
+ if (size == 0)
+ free (value.data);
+
need_break = 1;
} else {
gf_log ("bdb-ll", GF_LOG_DEBUG,
diff --git a/xlators/storage/bdb/src/bdb.c b/xlators/storage/bdb/src/bdb.c
index 81ced573e7f..086d7d9e73f 100644
--- a/xlators/storage/bdb/src/bdb.c
+++ b/xlators/storage/bdb/src/bdb.c
@@ -519,7 +519,7 @@ bdb_readv (call_frame_t *frame,
vec.iov_len = read_size;
stbuf.st_ino = fd->inode->ino;
- stbuf.st_size = op_ret ;
+ stbuf.st_size = bdb_db_fread (bfd, NULL, 0, 0);
stbuf.st_blocks = BDB_COUNT_BLOCKS (stbuf.st_size, stbuf.st_blksize);
op_ret = size;
out: