diff options
author | Amar Tumballi <amar@gluster.com> | 2010-08-21 01:50:31 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2010-08-21 05:17:27 -0700 |
commit | daf868e13511d97492ca4ece5fe60a2a4f69a20f (patch) | |
tree | d0a222781b0fd99e2d713fdc8b7dcdc8c2f8631b /glusterfsd | |
parent | c429e47ae3925d0bc1ca113e37d903410f3e043a (diff) |
portmapper program added to glusterfsd mgmt rpc
* some bug fixes glusterd-pmap.c
* also renamed 'fetch-spec.c' -> 'glusterfsd-mgmt.c'
Signed-off-by: Amar Tumballi <amar@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 1314 (portmapper functionality)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1314
Diffstat (limited to 'glusterfsd')
-rw-r--r-- | glusterfsd/src/Makefile.am | 2 | ||||
-rw-r--r-- | glusterfsd/src/glusterfsd-mgmt.c (renamed from glusterfsd/src/fetch-spec.c) | 156 | ||||
-rw-r--r-- | glusterfsd/src/glusterfsd.c | 25 | ||||
-rw-r--r-- | glusterfsd/src/glusterfsd.h | 5 |
4 files changed, 183 insertions, 5 deletions
diff --git a/glusterfsd/src/Makefile.am b/glusterfsd/src/Makefile.am index af4ce65fa..8cfe4b554 100644 --- a/glusterfsd/src/Makefile.am +++ b/glusterfsd/src/Makefile.am @@ -1,6 +1,6 @@ sbin_PROGRAMS = glusterfsd -glusterfsd_SOURCES = glusterfsd.c fetch-spec.c +glusterfsd_SOURCES = glusterfsd.c glusterfsd-mgmt.c if GF_DARWIN_HOST_OS glusterfsd_SOURCES += $(CONTRIBDIR)/apple/daemon.c endif diff --git a/glusterfsd/src/fetch-spec.c b/glusterfsd/src/glusterfsd-mgmt.c index d9e31b3ec..e6cfa6ac6 100644 --- a/glusterfsd/src/fetch-spec.c +++ b/glusterfsd/src/glusterfsd-mgmt.c @@ -36,10 +36,30 @@ #include "rpc-clnt.h" #include "protocol-common.h" #include "glusterfs3.h" +#include "portmap.h" +static char is_mgmt_rpc_reconnect; typedef ssize_t (*mgmt_serialize_t) (struct iovec outmsg, void *args); + +char *clnt_pmap_procs[GF_PMAP_MAXVALUE] = { + [GF_PMAP_NULL] = "NULL", + [GF_PMAP_PORTBYBRICK] = "PORTBYBRICK", + [GF_PMAP_BRICKBYPORT] = "BRICKBYPORT", + [GF_PMAP_SIGNIN] = "SIGNIN", + [GF_PMAP_SIGNOUT] = "SIGNOUT", + [GF_PMAP_SIGNUP] = "SIGNUP", +}; + + +rpc_clnt_prog_t clnt_pmap_prog = { + .progname = "Gluster Portmap", + .prognum = GLUSTER_PMAP_PROGRAM, + .progver = GLUSTER_PMAP_VERSION, + .procnames = clnt_pmap_procs, +}; + char *clnt_handshake_procs[GF_HNDSK_MAXVALUE] = { [GF_HNDSK_NULL] = "NULL", [GF_HNDSK_SETVOLUME] = "SETVOLUME", @@ -55,6 +75,7 @@ rpc_clnt_prog_t clnt_handshake_prog = { }; +int glusterfs_mgmt_pmap_signin (glusterfs_ctx_t *ctx); int glusterfs_volfile_fetch (glusterfs_ctx_t *ctx); int glusterfs_process_volfp (glusterfs_ctx_t *ctx, FILE *fp); @@ -161,13 +182,16 @@ mgmt_getspec_cbk (struct rpc_req *req, struct iovec *iov, int count, fwrite (rsp.spec, size, 1, tmpfp); fflush (tmpfp); - ret = glusterfs_process_volfp (ctx, tmpfp); if (ret) goto out; oldvollen = size; memcpy (oldvolfile, rsp.spec, size); + if (!is_mgmt_rpc_reconnect) { + glusterfs_mgmt_pmap_signin (ctx); + is_mgmt_rpc_reconnect = 1; + } out: tv.tv_sec = 1; @@ -192,7 +216,6 @@ glusterfs_volfile_fetch (glusterfs_ctx_t *ctx) int ret = 0; call_frame_t *frame = NULL; - { if (timer) gf_timer_call_cancel (ctx, timer); @@ -230,6 +253,8 @@ mgmt_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, ret = glusterfs_volfile_fetch (ctx); + if (is_mgmt_rpc_reconnect) + glusterfs_mgmt_pmap_signin (ctx); break; default: break; @@ -297,3 +322,130 @@ out: return ret; } + +static int +mgmt_pmap_signin_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + pmap_signin_rsp rsp = {0,}; + call_frame_t *frame = NULL; + int ret = 0; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = xdr_to_pmap_signin_rsp (*iov, &rsp); + if (ret < 0) { + gf_log (frame->this->name, GF_LOG_ERROR, "error"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (-1 == rsp.op_ret) { + gf_log (frame->this->name, GF_LOG_ERROR, + "failed to register the port with glusterd"); + goto out; + } +out: + + STACK_DESTROY (frame->root); + return 0; +} + +int +glusterfs_mgmt_pmap_signin (glusterfs_ctx_t *ctx) +{ + call_frame_t *frame = NULL; + pmap_signin_req req = {0, }; + int ret = -1; + cmd_args_t *cmd_args = NULL; + + frame = create_frame (THIS, ctx->pool); + cmd_args = &ctx->cmd_args; + + if (!cmd_args->brick_port || !cmd_args->brick_name) { + gf_log ("fsd-mgmt", GF_LOG_DEBUG, + "portmapper signin arguments not given"); + goto out; + } + + req.port = cmd_args->brick_port; + req.brick = cmd_args->brick_name; + + ret = mgmt_submit_request (&req, frame, ctx, &clnt_pmap_prog, + GF_PMAP_SIGNIN, xdr_from_pmap_signin_req, + mgmt_pmap_signin_cbk); + +out: + return ret; +} + + +static int +mgmt_pmap_signout_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + pmap_signout_rsp rsp = {0,}; + call_frame_t *frame = NULL; + int ret = 0; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = xdr_to_pmap_signout_rsp (*iov, &rsp); + if (ret < 0) { + gf_log (frame->this->name, GF_LOG_ERROR, "error"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (-1 == rsp.op_ret) { + gf_log (frame->this->name, GF_LOG_ERROR, + "failed to register the port with glusterd"); + goto out; + } +out: + if (frame) + STACK_DESTROY (frame->root); + return 0; +} + + +int +glusterfs_mgmt_pmap_signout (glusterfs_ctx_t *ctx) +{ + int ret = 0; + pmap_signout_req req = {0, }; + call_frame_t *frame = NULL; + cmd_args_t *cmd_args = NULL; + + frame = create_frame (THIS, ctx->pool); + cmd_args = &ctx->cmd_args; + + if (!cmd_args->brick_port || !cmd_args->brick_name) { + gf_log ("fsd-mgmt", GF_LOG_DEBUG, + "portmapper signout arguments not given"); + goto out; + } + + req.port = cmd_args->brick_port; + req.brick = cmd_args->brick_name; + + ret = mgmt_submit_request (&req, frame, ctx, &clnt_pmap_prog, + GF_PMAP_SIGNOUT, xdr_from_pmap_signout_req, + mgmt_pmap_signout_cbk); +out: + return ret; +} diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c index 6daeac129..c944075f7 100644 --- a/glusterfsd/src/glusterfsd.c +++ b/glusterfsd/src/glusterfsd.c @@ -157,7 +157,11 @@ static struct argp_option gf_options[] = { #else "[default: \"off\"]" #endif - }, + }, + {"brick-name", ARGP_BRICK_NAME_KEY, "BRICK-NAME", OPTION_HIDDEN, + "Brick name to be registered with Gluster portmapper" }, + {"brick-port", ARGP_BRICK_PORT_KEY, "BRICK-PORT", OPTION_HIDDEN, + "Brick Port to be registered with Gluster portmapper" }, {0, 0, 0, 0, "Fuse options:"}, {"direct-io-mode", ARGP_DIRECT_IO_MODE_KEY, "BOOL", OPTION_ARG_OPTIONAL, @@ -574,6 +578,20 @@ parse_opts (int key, char *arg, struct argp_state *state) case ARGP_DUMP_FUSE_KEY: cmd_args->dump_fuse = gf_strdup (arg); break; + case ARGP_BRICK_NAME_KEY: + cmd_args->brick_name = gf_strdup (arg); + break; + case ARGP_BRICK_PORT_KEY: + n = 0; + + if (gf_string2uint_base10 (arg, &n) == 0) { + cmd_args->brick_port = n; + break; + } + + argp_failure (state, -1, 0, + "unknown brick (listen) port %s", arg); + break; } return 0; @@ -588,13 +606,16 @@ cleanup_and_exit (int signum) ctx = glusterfs_ctx_get (); + /* TODO: is this the right place? */ + glusterfs_mgmt_pmap_signout (ctx); + gf_log ("glusterfsd", GF_LOG_NORMAL, "shutting down"); tmp_pool = ctx->pool; mem_pool_destroy (tmp_pool->frame_mem_pool); mem_pool_destroy (tmp_pool->stack_mem_pool); tmp_pool = NULL; - mem_pool_destroy (ctx->stub_mem_pool); + mem_pool_destroy (ctx->stub_mem_pool); glusterfs_pidfile_cleanup (ctx); diff --git a/glusterfsd/src/glusterfsd.h b/glusterfsd/src/glusterfsd.h index 7827c9800..a082b0e4b 100644 --- a/glusterfsd/src/glusterfsd.h +++ b/glusterfsd/src/glusterfsd.h @@ -73,10 +73,15 @@ enum argp_option_keys { ARGP_READ_ONLY_KEY = 148, ARGP_MAC_COMPAT_KEY = 149, ARGP_DUMP_FUSE_KEY = 150, + ARGP_BRICK_NAME_KEY = 151, + ARGP_BRICK_PORT_KEY = 152, }; /* Moved here from fetch-spec.h */ FILE *fetch_spec (glusterfs_ctx_t *ctx); +int glusterfs_mgmt_pmap_signout (glusterfs_ctx_t *ctx); +int glusterfs_mgmt_pmap_signin (glusterfs_ctx_t *ctx); + #endif /* __GLUSTERFSD_H__ */ |