From 7a3c372c7a8a3ad7d481f94a899fd4333d146634 Mon Sep 17 00:00:00 2001 From: Anand Avati Date: Sun, 6 Dec 2009 04:44:59 +0000 Subject: libglusterfsclient: fix libgf_client_read to handle short reads Fixes two issues in the current code -short reads (reading larger than file size) result in failure of full read -reads which span multiple iterations return with the op_ret of only the last read Signed-off-by: Anand V. Avati Signed-off-by: Anand V. Avati BUG: 334 (glusterfs_read/readv should break large-reads into 128Kb block sizes) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=334 --- libglusterfsclient/src/libglusterfsclient.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'libglusterfsclient') diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index f90de48c3ad..692f46d9214 100755 --- a/libglusterfsclient/src/libglusterfsclient.c +++ b/libglusterfsclient/src/libglusterfsclient.c @@ -3703,22 +3703,29 @@ libgf_client_read (libglusterfs_client_ctx_t *ctx, fd_t *fd, void *buf, size_t size, off_t offset) { int32_t op_ret = -1; + int32_t ret = 0; size_t tmp = 0; while (size != 0) { tmp = ((size > LIBGF_IOBUF_SIZE) ? LIBGF_IOBUF_SIZE : size); op_ret = libgf_client_iobuf_read (ctx, fd, buf, tmp, offset); - if (op_ret <= 0) { + if (op_ret < 0) { + ret = op_ret; break; } + ret += op_ret; + + if (op_ret < tmp) + break; + size -= op_ret; offset += op_ret; buf = (char *)buf + op_ret; } - return op_ret; + return ret; } ssize_t -- cgit