From 38afd84faa383c5e0be21c48c918112b7b01a5cf Mon Sep 17 00:00:00 2001 From: Anand Avati Date: Mon, 20 Aug 2012 10:19:15 -0700 Subject: rpcsvc: framework for executing actors as synctask An rpcsvc_program can be registered by setting .synctask field to 1 which will make actors of that program be executed in a synctask, thus freeing up the rpc/poll thread while the actor executes. Change-Id: Idacef2ad3bcae0f354fd0fc16ca06ba7094d7b98 BUG: 762935 Signed-off-by: Anand Avati Reviewed-on: http://review.gluster.org/3833 Tested-by: Gluster Build System Reviewed-by: Amar Tumballi --- rpc/rpc-lib/src/rpcsvc.c | 24 +++++++++++++++++++++++- rpc/rpc-lib/src/rpcsvc.h | 6 ++++++ xlators/mgmt/glusterd/src/glusterd-handler.c | 3 +++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/rpc/rpc-lib/src/rpcsvc.c b/rpc/rpc-lib/src/rpcsvc.c index ca637a506..ad1e4f478 100644 --- a/rpc/rpc-lib/src/rpcsvc.c +++ b/rpc/rpc-lib/src/rpcsvc.c @@ -27,6 +27,7 @@ #include "xdr-common.h" #include "xdr-generic.h" #include "rpc-common-xdr.h" +#include "syncop.h" #include #include @@ -206,6 +207,8 @@ rpcsvc_program_actor (rpcsvc_request_t *req) goto err; } + req->synctask = program->synctask; + err = SUCCESS; gf_log (GF_RPCSVC, GF_LOG_TRACE, "Actor found: %s - %s", program->progname, actor->procname); @@ -430,6 +433,20 @@ err: } +int +rpcsvc_synctask_cbk (int ret, call_frame_t *frame, void *opaque) +{ + rpcsvc_request_t *req = NULL; + + req = opaque; + + if (ret == RPCSVC_ACTOR_ERROR) + rpcsvc_error_reply (req); + + return 0; +} + + int rpcsvc_handle_rpc_call (rpcsvc_t *svc, rpc_transport_t *trans, rpc_transport_pollin_t *msg) @@ -510,7 +527,12 @@ rpcsvc_handle_rpc_call (rpcsvc_t *svc, rpc_transport_t *trans, goto err_reply; } - ret = actor_fn (req); + if (req->synctask) + ret = synctask_new (THIS->ctx->env, + (synctask_fn_t) actor_fn, + rpcsvc_synctask_cbk, NULL, req); + else + ret = actor_fn (req); } err_reply: diff --git a/rpc/rpc-lib/src/rpcsvc.h b/rpc/rpc-lib/src/rpcsvc.h index 9f526cb05..5a0ddc9da 100644 --- a/rpc/rpc-lib/src/rpcsvc.h +++ b/rpc/rpc-lib/src/rpcsvc.h @@ -224,6 +224,9 @@ struct rpcsvc_request { */ rpcsvc_auth_data_t verf; + /* Execute this request's actor function as a synctask? */ + gf_boolean_t synctask; + /* Container for a RPC program wanting to store a temp * request-specific item. */ @@ -367,6 +370,9 @@ struct rpcsvc_program { */ int min_auth; + /* Execute actor function as a synctask? */ + gf_boolean_t synctask; + /* list member to link to list of registered services with rpcsvc */ struct list_head program; }; diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index dd88ed0c2..01f2adb38 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -2961,6 +2961,7 @@ struct rpcsvc_program gd_svc_mgmt_prog = { .progver = GD_MGMT_VERSION, .numactors = GLUSTERD_MGMT_MAXVALUE, .actors = gd_svc_mgmt_actors, + .synctask = _gf_false, }; rpcsvc_actor_t gd_svc_peer_actors[] = { @@ -2977,6 +2978,7 @@ struct rpcsvc_program gd_svc_peer_prog = { .progver = GD_FRIEND_VERSION, .numactors = GLUSTERD_FRIEND_MAXVALUE, .actors = gd_svc_peer_actors, + .synctask = _gf_false, }; @@ -3018,4 +3020,5 @@ struct rpcsvc_program gd_svc_cli_prog = { .progver = GLUSTER_CLI_VERSION, .numactors = GLUSTER_CLI_MAXVALUE, .actors = gd_svc_cli_actors, + .synctask = _gf_false, }; -- cgit