diff options
-rw-r--r-- | libglusterfs/src/mem-types.h | 3 | ||||
-rw-r--r-- | rpc/rpc-lib/src/rpc-clnt.c | 54 |
2 files changed, 48 insertions, 9 deletions
diff --git a/libglusterfs/src/mem-types.h b/libglusterfs/src/mem-types.h index 9450af89210..16dd93ffc7e 100644 --- a/libglusterfs/src/mem-types.h +++ b/libglusterfs/src/mem-types.h @@ -96,6 +96,7 @@ enum gf_common_mem_types_ { gf_common_mt_rdma_device_t = 71, gf_common_mt_rdma_context_t = 72, gf_common_mt_sge = 73, - gf_common_mt_end = 74 + gf_common_mt_rpcclnt_cb_program_t = 74, + gf_common_mt_end = 75 }; #endif diff --git a/rpc/rpc-lib/src/rpc-clnt.c b/rpc/rpc-lib/src/rpc-clnt.c index bd878f4fc1e..fa3bc81ffe8 100644 --- a/rpc/rpc-lib/src/rpc-clnt.c +++ b/rpc/rpc-lib/src/rpc-clnt.c @@ -692,13 +692,19 @@ rpc_clnt_handle_cbk (struct rpc_clnt *clnt, rpc_transport_pollin_t *msg) procnum = rpc_call_progproc (&rpcmsg); - list_for_each_entry (program, &clnt->programs, program) { - if ((program->prognum == rpc_call_program (&rpcmsg)) - && (program->progver == rpc_call_progver (&rpcmsg))) { - found = 1; - break; + pthread_mutex_lock (&clnt->lock); + { + list_for_each_entry (program, &clnt->programs, program) { + if ((program->prognum == rpc_call_program (&rpcmsg)) + && (program->progver + == rpc_call_progver (&rpcmsg))) { + found = 1; + break; + } } } + pthread_mutex_unlock (&clnt->lock); + if (found && (procnum < program->numactors) && (program->actors[procnum].actor)) { program->actors[procnum].actor (&progmsg); @@ -1241,7 +1247,9 @@ int rpcclnt_cbk_program_register (struct rpc_clnt *clnt, rpcclnt_cb_program_t *program) { - int ret = -1; + int ret = -1; + char already_registered = 0; + rpcclnt_cb_program_t *tmp = NULL; if (!clnt) goto out; @@ -1249,9 +1257,39 @@ rpcclnt_cbk_program_register (struct rpc_clnt *clnt, if (program->actors == NULL) goto out; - INIT_LIST_HEAD (&program->program); + pthread_mutex_lock (&clnt->lock); + { + list_for_each_entry (tmp, &clnt->programs, program) { + if ((program->prognum == tmp->prognum) + && (program->progver == tmp->progver)) { + already_registered = 1; + break; + } + } + } + pthread_mutex_unlock (&clnt->lock); + + if (already_registered) { + gf_log ("rpc-clnt", GF_LOG_DEBUG, "already registered"); + ret = 0; + goto out; + } + + tmp = GF_CALLOC (1, sizeof (*tmp), + gf_common_mt_rpcclnt_cb_program_t); + if (tmp == NULL) { + gf_log ("rpc-clnt", GF_LOG_ERROR, "out of memory"); + goto out; + } + + memcpy (tmp, program, sizeof (*tmp)); + INIT_LIST_HEAD (&tmp->program); - list_add_tail (&program->program, &clnt->programs); + pthread_mutex_lock (&clnt->lock); + { + list_add_tail (&tmp->program, &clnt->programs); + } + pthread_mutex_unlock (&clnt->lock); ret = 0; gf_log ("rpc-clnt", GF_LOG_DEBUG, "New program registered: %s, Num: %d," |