From a4a0054caee6c75ae442d4984b95bf9753eded36 Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Wed, 3 Jun 2009 01:05:42 +0000 Subject: 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 --- libglusterfsclient/src/libglusterfsclient-internals.h | 5 +++++ libglusterfsclient/src/libglusterfsclient.c | 18 +++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'libglusterfsclient') diff --git a/libglusterfsclient/src/libglusterfsclient-internals.h b/libglusterfsclient/src/libglusterfsclient-internals.h index fc79a539..d55cfb1f 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 c05918e2..9399d2c2 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; -- cgit