From b0acbf09c21ff898ad3315811974e49cc80e6f2b Mon Sep 17 00:00:00 2001 From: Basavanagowda Kanur Date: Thu, 23 Apr 2009 04:05:00 +0530 Subject: 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 --- xlators/storage/bdb/src/bdb-ll.c | 26 +++++++++++++++++--------- xlators/storage/bdb/src/bdb.c | 2 +- 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: -- cgit