summaryrefslogtreecommitdiffstats
path: root/libglusterfsclient
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@gluster.com>2009-06-03 01:05:42 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-06-08 06:31:56 -0700
commita4a0054caee6c75ae442d4984b95bf9753eded36 (patch)
treee5ce12d2d0330280f0ac519f2a721f2a78e404db /libglusterfsclient
parent4c0b91a5a045e3f03a049320d26542ab9fec4745 (diff)
libglusterfsclient: Avoid dirent copies in readdir cbk
We can avoid memory allocation, de-allocation and data copies by just using the entries passed to us from a lower layer and by de-linking the entries from the original list. Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
Diffstat (limited to 'libglusterfsclient')
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient-internals.h5
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.c18
2 files changed, 16 insertions, 7 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient-internals.h b/libglusterfsclient/src/libglusterfsclient-internals.h
index fc79a539d69..d55cfb1f5f6 100755
--- a/libglusterfsclient/src/libglusterfsclient-internals.h
+++ b/libglusterfsclient/src/libglusterfsclient-internals.h
@@ -64,6 +64,11 @@ typedef struct {
int32_t size;
} lookup;
}fop;
+ fd_t *dirfd; /* Needed here because we need a ref to the dir
+ fd in the libgf_client_readdir_cbk in order
+ to process the dirents received, without
+ having them added to the reply stub.
+ */
}libgf_client_local_t;
typedef struct {
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c
index c05918e2148..9399d2c29b4 100755
--- a/libglusterfsclient/src/libglusterfsclient.c
+++ b/libglusterfsclient/src/libglusterfsclient.c
@@ -3489,9 +3489,15 @@ libgf_client_readdir_cbk (call_frame_t *frame,
{
libgf_client_local_t *local = frame->local;
+ /* Note, we dont let entries reach the stub because there it gets copied
+ * while we can simply delink the entries here and link them into our
+ * dcache, thereby avoiding the need to perform more allocations and
+ * copies.
+ */
local->reply_stub = fop_readdir_cbk_stub (frame, NULL, op_ret, op_errno,
- entries);
-
+ NULL);
+ if (op_ret > 0)
+ libgf_dcache_update (frame->root->state, local->dirfd, entries);
LIBGF_REPLY_NOTIFY (local);
return 0;
}
@@ -3506,16 +3512,14 @@ libgf_client_readdir (libglusterfs_client_ctx_t *ctx, fd_t *fd,
if (libgf_dcache_readdir (ctx, fd, dirp, offset))
return 1;
-
+ local = CALLOC (1, sizeof (*local));
+ ERR_ABORT (local);
+ local->dirfd = fd;
LIBGF_CLIENT_FOP (ctx, stub, readdir, local, fd,
LIBGF_READDIR_BLOCK, *offset);
- op_ret = stub->args.readdir_cbk.op_ret;
errno = stub->args.readdir_cbk.op_errno;
- if (op_ret > 0)
- libgf_dcache_update (ctx, fd, &stub->args.readdir_cbk.entries);
-
op_ret = libgf_dcache_readdir (ctx, fd, dirp, offset);
call_stub_destroy (stub);
return op_ret;