From cd13c7e7368ec60ec9b6559e2eced41bcc10d6bc Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Thu, 24 Sep 2009 00:49:50 +0000 Subject: libglusterfsclient: Wait for all call pools to be destroyed This ensures that the process using libglusterfsclient does not exit before all the fops and calls have been replied to. It helps to ensure that the backends are in a sane state when the program exits. Signed-off-by: Anand V. Avati BUG: 279 (File written with booster results in self-heal after dd exits) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=279 --- libglusterfsclient/src/libglusterfsclient.c | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'libglusterfsclient') diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index 0f2c2dd80a6..8ed1493faa5 100755 --- a/libglusterfsclient/src/libglusterfsclient.c +++ b/libglusterfsclient/src/libglusterfsclient.c @@ -1816,11 +1816,45 @@ void glusterfs_log_unlock (void) } +void +libgf_wait_for_frames_unwind (libglusterfs_client_ctx_t *ctx) +{ + call_pool_t *pool = NULL; + int canreturn = 0; + + if (!ctx) + return; + + pool = (call_pool_t *)ctx->gf_ctx.pool; + while (1) { + LOCK (&pool->lock); + { + if (pool->cnt == 0) { + canreturn = 1; + goto unlock_out; + } + } +unlock_out: + UNLOCK (&pool->lock); + + if (canreturn) + break; + + gf_log (LIBGF_XL_NAME, GF_LOG_DEBUG, "Waiting for call frames"); + sleep (1); + } + + return; +} + + int glusterfs_fini (glusterfs_handle_t handle) { libglusterfs_client_ctx_t *ctx = handle; + libgf_wait_for_frames_unwind (ctx); + FREE (ctx->gf_ctx.cmd_args.log_file); FREE (ctx->gf_ctx.cmd_args.volume_file); FREE (ctx->gf_ctx.cmd_args.volume_name); -- cgit