diff options
author | Raghavendra G <raghavendra@gluster.com> | 2010-10-08 07:01:42 +0000 |
---|---|---|
committer | Vijay Bellur <vijay@dev.gluster.com> | 2010-10-08 06:05:06 -0700 |
commit | 09914c02f24b4cc74cb6aad9994ae590cf8b76bf (patch) | |
tree | 19570d4acb3d50a2267530f4f62b607847153eda | |
parent | 2e43696eb90dc835d0aa8000e19b6f207760309c (diff) |
rpc/clnt: allocate a new cbk_program before registering it.
- Refer Bug 1836 for more details.
Signed-off-by: Raghavendra G <raghavendra@gluster.com>
Signed-off-by: Vijay Bellur <vijay@dev.gluster.com>
BUG: 1862 ()
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1862
-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 9450af892..16dd93ffc 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 bd878f4fc..fa3bc81ff 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," |