diff options
author | Raghavendra G <raghavendra@gluster.com> | 2009-12-01 14:39:45 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2009-12-01 17:52:43 -0800 |
commit | 6afe4faeaa77911490b2eca0830928367543e504 (patch) | |
tree | 40fefebd5c5452576887fd6691ed02ca177810bb /libglusterfsclient/src | |
parent | 435b234325bdcdcea88c3e1c7e9d97deeee3eb9a (diff) |
libglusterfsclient/read: break reads bigger than the iobuffer size into smaller ones.
Signed-off-by: Raghavendra G <raghavendra@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
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
Diffstat (limited to 'libglusterfsclient/src')
-rwxr-xr-x | libglusterfsclient/src/libglusterfsclient.c | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index 85c9e3c9e..456323778 100755 --- a/libglusterfsclient/src/libglusterfsclient.c +++ b/libglusterfsclient/src/libglusterfsclient.c @@ -3628,19 +3628,16 @@ libgf_client_readv_cbk (call_frame_t *frame, return 0; } -int -libgf_client_read (libglusterfs_client_ctx_t *ctx, - fd_t *fd, - void *buf, - size_t size, - off_t offset) +int +libgf_client_iobuf_read (libglusterfs_client_ctx_t *ctx, fd_t *fd, void *buf, + size_t size, off_t offset) { - call_stub_t *stub; - struct iovec *vector; - int32_t op_ret = -1; - int count = 0; + call_stub_t *stub = NULL; + struct iovec *vector = NULL; + int32_t op_ret = -1; + int count = 0; libgf_client_local_t *local = NULL; - struct stat *stbuf = NULL; + struct stat *stbuf = NULL; local = CALLOC (1, sizeof (*local)); ERR_ABORT (local); @@ -3655,7 +3652,7 @@ libgf_client_read (libglusterfs_client_ctx_t *ctx, int i = 0; op_ret = 0; while (size && (i < count)) { - int len = (size < vector[i].iov_len) ? + int len = (size < vector[i].iov_len) ? size : vector[i].iov_len; memcpy (buf, vector[i++].iov_base, len); buf += len; @@ -3673,10 +3670,31 @@ libgf_client_read (libglusterfs_client_ctx_t *ctx, return op_ret; } -ssize_t -glusterfs_read (glusterfs_file_t fd, - void *buf, - size_t nbytes) +int +libgf_client_read (libglusterfs_client_ctx_t *ctx, fd_t *fd, void *buf, + size_t size, off_t offset) +{ + int32_t op_ret = -1; + 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) { + break; + } + + size -= op_ret; + offset += op_ret; + buf = (char *)buf + op_ret; + } + + return op_ret; +} + +ssize_t +glusterfs_read (glusterfs_file_t fd, void *buf, size_t nbytes) { int32_t op_ret = -1; off_t offset = 0; |