From daf868e13511d97492ca4ece5fe60a2a4f69a20f Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Sat, 21 Aug 2010 01:50:31 +0000 Subject: 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 Signed-off-by: Anand V. Avati BUG: 1314 (portmapper functionality) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1314 --- glusterfsd/src/Makefile.am | 2 +- glusterfsd/src/fetch-spec.c | 299 ---------------- glusterfsd/src/glusterfsd-mgmt.c | 451 +++++++++++++++++++++++++ glusterfsd/src/glusterfsd.c | 25 +- glusterfsd/src/glusterfsd.h | 5 + libglusterfs/src/glusterfs.h | 4 + xlators/mgmt/glusterd/src/glusterd-handshake.c | 41 ++- xlators/mgmt/glusterd/src/glusterd-pmap.c | 52 ++- xlators/mgmt/glusterd/src/glusterd-pmap.h | 1 + xlators/mgmt/glusterd/src/glusterd-utils.c | 14 +- 10 files changed, 579 insertions(+), 315 deletions(-) delete mode 100644 glusterfsd/src/fetch-spec.c create mode 100644 glusterfsd/src/glusterfsd-mgmt.c diff --git a/glusterfsd/src/Makefile.am b/glusterfsd/src/Makefile.am index af4ce65fab4..8cfe4b55461 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/fetch-spec.c deleted file mode 100644 index d9e31b3ecdb..00000000000 --- a/glusterfsd/src/fetch-spec.c +++ /dev/null @@ -1,299 +0,0 @@ -/* - Copyright (c) 2007-2009 Gluster, Inc. - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - . -*/ - -#include -#include -#include -#include - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif /* _CONFIG_H */ - -#include "glusterfs.h" -#include "stack.h" -#include "dict.h" -#include "event.h" -#include "defaults.h" - -#include "rpc-clnt.h" -#include "protocol-common.h" -#include "glusterfs3.h" - - -typedef ssize_t (*mgmt_serialize_t) (struct iovec outmsg, void *args); - -char *clnt_handshake_procs[GF_HNDSK_MAXVALUE] = { - [GF_HNDSK_NULL] = "NULL", - [GF_HNDSK_SETVOLUME] = "SETVOLUME", - [GF_HNDSK_GETSPEC] = "GETSPEC", - [GF_HNDSK_PING] = "PING", -}; - -rpc_clnt_prog_t clnt_handshake_prog = { - .progname = "GlusterFS Handshake", - .prognum = GLUSTER_HNDSK_PROGRAM, - .progver = GLUSTER_HNDSK_VERSION, - .procnames = clnt_handshake_procs, -}; - - -int glusterfs_volfile_fetch (glusterfs_ctx_t *ctx); -int glusterfs_process_volfp (glusterfs_ctx_t *ctx, FILE *fp); - -int -mgmt_submit_request (void *req, call_frame_t *frame, - glusterfs_ctx_t *ctx, - rpc_clnt_prog_t *prog, int procnum, - mgmt_serialize_t sfunc, fop_cbk_fn_t cbkfn) -{ - int ret = -1; - int count = 0; - struct iovec iov = {0, }; - struct iobuf *iobuf = NULL; - struct iobref *iobref = NULL; - - iobref = iobref_new (); - if (!iobref) { - goto out; - } - - iobuf = iobuf_get (ctx->iobuf_pool); - if (!iobuf) { - goto out; - }; - - iobref_add (iobref, iobuf); - - iov.iov_base = iobuf->ptr; - iov.iov_len = 128 * GF_UNIT_KB; - - - /* Create the xdr payload */ - if (req && sfunc) { - ret = sfunc (iov, req); - if (ret == -1) { - goto out; - } - iov.iov_len = ret; - count = 1; - } - - /* Send the msg */ - ret = rpc_clnt_submit (ctx->mgmt, prog, procnum, cbkfn, - &iov, count, - NULL, 0, iobref, frame, NULL, 0, NULL, 0, NULL); - -out: - if (iobref) - iobref_unref (iobref); - - return ret; -} - - -/* XXX: move these into @ctx */ -static char oldvolfile[131072]; -static int oldvollen = 0; -static void *timer; - -int -mgmt_getspec_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - gf_getspec_rsp rsp = {0,}; - call_frame_t *frame = NULL; - glusterfs_ctx_t *ctx = NULL; - int ret = 0; - ssize_t size = 0; - FILE *tmpfp = NULL; - struct timeval tv = {0, }; - - frame = myframe; - ctx = frame->this->ctx; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - ret = xdr_to_getspec_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 get the 'volume file' from server"); - goto out; - } - - size = rsp.op_ret; - - if (size == oldvollen && (memcmp (oldvolfile, rsp.spec, size) == 0)) - goto out; - - tmpfp = tmpfile (); - if (!tmpfp) - goto out; - - 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); - -out: - tv.tv_sec = 1; - timer = gf_timer_call_after (ctx, tv, - (gf_timer_cbk_t) glusterfs_volfile_fetch, - ctx); - - STACK_DESTROY (frame->root); - - if (rsp.spec) - free (rsp.spec); - - return 0; -} - - -int -glusterfs_volfile_fetch (glusterfs_ctx_t *ctx) -{ - cmd_args_t *cmd_args = NULL; - gf_getspec_req req = {0, }; - int ret = 0; - call_frame_t *frame = NULL; - - - { - if (timer) - gf_timer_call_cancel (ctx, timer); - timer = NULL; - } - - cmd_args = &ctx->cmd_args; - - frame = create_frame (THIS, ctx->pool); - - req.key = cmd_args->volfile_id; - req.flags = 0; - - ret = mgmt_submit_request (&req, frame, ctx, &clnt_handshake_prog, - GF_HNDSK_GETSPEC, xdr_from_getspec_req, - mgmt_getspec_cbk); - return ret; -} - - -static int -mgmt_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, - void *data) -{ - xlator_t *this = NULL; - glusterfs_ctx_t *ctx = NULL; - int ret = 0; - - this = mydata; - ctx = this->ctx; - - switch (event) { - case RPC_CLNT_CONNECT: - rpc_clnt_set_connected (ctx->mgmt); - - ret = glusterfs_volfile_fetch (ctx); - - break; - default: - break; - } - - return 0; -} - - -int -glusterfs_mgmt_init (glusterfs_ctx_t *ctx) -{ - cmd_args_t *cmd_args = NULL; - struct rpc_clnt *rpc = NULL; - struct rpc_clnt_config rpc_cfg = {0,}; - dict_t *options = NULL; - int ret = -1; - int port = 6969; - char *host = NULL; - - cmd_args = &ctx->cmd_args; - - if (ctx->mgmt) - return 0; - - options = dict_new (); - if (!options) - goto out; - - if (cmd_args->volfile_server_port) - port = cmd_args->volfile_server_port; - - host = "localhost"; - if (cmd_args->volfile_server) - host = cmd_args->volfile_server; - - rpc_cfg.remote_host = host; - rpc_cfg.remote_port = port; - - ret = dict_set_int32 (options, "remote-port", port); - if (ret) - goto out; - - ret = dict_set_str (options, "remote-host", host); - if (ret) - goto out; - - ret = dict_set_str (options, "transport.address-family", "inet"); - if (ret) - goto out; - - rpc = rpc_clnt_init (&rpc_cfg, options, THIS->ctx, THIS->name); - if (!rpc) { - ret = -1; - goto out; - } - - ctx->mgmt = rpc; - - ret = rpc_clnt_register_notify (rpc, mgmt_rpc_notify, THIS); - if (ret) - goto out; - -out: - return ret; -} - diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c new file mode 100644 index 00000000000..e6cfa6ac6d1 --- /dev/null +++ b/glusterfsd/src/glusterfsd-mgmt.c @@ -0,0 +1,451 @@ +/* + Copyright (c) 2007-2009 Gluster, Inc. + This file is part of GlusterFS. + + GlusterFS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3 of the License, + or (at your option) any later version. + + GlusterFS is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see + . +*/ + +#include +#include +#include +#include + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif /* _CONFIG_H */ + +#include "glusterfs.h" +#include "stack.h" +#include "dict.h" +#include "event.h" +#include "defaults.h" + +#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", + [GF_HNDSK_GETSPEC] = "GETSPEC", + [GF_HNDSK_PING] = "PING", +}; + +rpc_clnt_prog_t clnt_handshake_prog = { + .progname = "GlusterFS Handshake", + .prognum = GLUSTER_HNDSK_PROGRAM, + .progver = GLUSTER_HNDSK_VERSION, + .procnames = clnt_handshake_procs, +}; + + +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); + +int +mgmt_submit_request (void *req, call_frame_t *frame, + glusterfs_ctx_t *ctx, + rpc_clnt_prog_t *prog, int procnum, + mgmt_serialize_t sfunc, fop_cbk_fn_t cbkfn) +{ + int ret = -1; + int count = 0; + struct iovec iov = {0, }; + struct iobuf *iobuf = NULL; + struct iobref *iobref = NULL; + + iobref = iobref_new (); + if (!iobref) { + goto out; + } + + iobuf = iobuf_get (ctx->iobuf_pool); + if (!iobuf) { + goto out; + }; + + iobref_add (iobref, iobuf); + + iov.iov_base = iobuf->ptr; + iov.iov_len = 128 * GF_UNIT_KB; + + + /* Create the xdr payload */ + if (req && sfunc) { + ret = sfunc (iov, req); + if (ret == -1) { + goto out; + } + iov.iov_len = ret; + count = 1; + } + + /* Send the msg */ + ret = rpc_clnt_submit (ctx->mgmt, prog, procnum, cbkfn, + &iov, count, + NULL, 0, iobref, frame, NULL, 0, NULL, 0, NULL); + +out: + if (iobref) + iobref_unref (iobref); + + return ret; +} + + +/* XXX: move these into @ctx */ +static char oldvolfile[131072]; +static int oldvollen = 0; +static void *timer; + +int +mgmt_getspec_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gf_getspec_rsp rsp = {0,}; + call_frame_t *frame = NULL; + glusterfs_ctx_t *ctx = NULL; + int ret = 0; + ssize_t size = 0; + FILE *tmpfp = NULL; + struct timeval tv = {0, }; + + frame = myframe; + ctx = frame->this->ctx; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = xdr_to_getspec_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 get the 'volume file' from server"); + goto out; + } + + size = rsp.op_ret; + + if (size == oldvollen && (memcmp (oldvolfile, rsp.spec, size) == 0)) + goto out; + + tmpfp = tmpfile (); + if (!tmpfp) + goto out; + + 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; + timer = gf_timer_call_after (ctx, tv, + (gf_timer_cbk_t) glusterfs_volfile_fetch, + ctx); + + STACK_DESTROY (frame->root); + + if (rsp.spec) + free (rsp.spec); + + return 0; +} + + +int +glusterfs_volfile_fetch (glusterfs_ctx_t *ctx) +{ + cmd_args_t *cmd_args = NULL; + gf_getspec_req req = {0, }; + int ret = 0; + call_frame_t *frame = NULL; + + { + if (timer) + gf_timer_call_cancel (ctx, timer); + timer = NULL; + } + + cmd_args = &ctx->cmd_args; + + frame = create_frame (THIS, ctx->pool); + + req.key = cmd_args->volfile_id; + req.flags = 0; + + ret = mgmt_submit_request (&req, frame, ctx, &clnt_handshake_prog, + GF_HNDSK_GETSPEC, xdr_from_getspec_req, + mgmt_getspec_cbk); + return ret; +} + + +static int +mgmt_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, + void *data) +{ + xlator_t *this = NULL; + glusterfs_ctx_t *ctx = NULL; + int ret = 0; + + this = mydata; + ctx = this->ctx; + + switch (event) { + case RPC_CLNT_CONNECT: + rpc_clnt_set_connected (ctx->mgmt); + + ret = glusterfs_volfile_fetch (ctx); + + if (is_mgmt_rpc_reconnect) + glusterfs_mgmt_pmap_signin (ctx); + break; + default: + break; + } + + return 0; +} + + +int +glusterfs_mgmt_init (glusterfs_ctx_t *ctx) +{ + cmd_args_t *cmd_args = NULL; + struct rpc_clnt *rpc = NULL; + struct rpc_clnt_config rpc_cfg = {0,}; + dict_t *options = NULL; + int ret = -1; + int port = 6969; + char *host = NULL; + + cmd_args = &ctx->cmd_args; + + if (ctx->mgmt) + return 0; + + options = dict_new (); + if (!options) + goto out; + + if (cmd_args->volfile_server_port) + port = cmd_args->volfile_server_port; + + host = "localhost"; + if (cmd_args->volfile_server) + host = cmd_args->volfile_server; + + rpc_cfg.remote_host = host; + rpc_cfg.remote_port = port; + + ret = dict_set_int32 (options, "remote-port", port); + if (ret) + goto out; + + ret = dict_set_str (options, "remote-host", host); + if (ret) + goto out; + + ret = dict_set_str (options, "transport.address-family", "inet"); + if (ret) + goto out; + + rpc = rpc_clnt_init (&rpc_cfg, options, THIS->ctx, THIS->name); + if (!rpc) { + ret = -1; + goto out; + } + + ctx->mgmt = rpc; + + ret = rpc_clnt_register_notify (rpc, mgmt_rpc_notify, THIS); + if (ret) + goto out; + +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 6daeac1293e..c944075f76f 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 7827c9800a7..a082b0e4b7f 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__ */ diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index 6f40b988024..4b157430b22 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -241,6 +241,10 @@ struct _cmd_args { /* key args */ char *mount_point; char *volfile_id; + + /* required for portmap */ + int brick_port; + char *brick_name; }; typedef struct _cmd_args cmd_args_t; diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c index 9f5e03f5306..43a93731790 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handshake.c +++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c @@ -42,13 +42,44 @@ static size_t build_volfile_path (const char *volname, char *path, size_t path_len) { - int32_t ret = -1; - glusterd_conf_t *priv = NULL; + struct stat stbuf = {0,}; + int32_t ret = -1; + glusterd_conf_t *priv = NULL; + char *vol = NULL; + char *dup_volname = NULL; + char *tmp = NULL; + glusterd_volinfo_t *volinfo = NULL; priv = THIS->private; + dup_volname = gf_strdup (volname); + + ret = glusterd_volinfo_find (dup_volname, &volinfo); + if (ret) { + /* Split the volume name */ + vol = strtok_r (dup_volname, "-", &tmp); + if (!vol) + goto out; + vol = strtok_r (NULL, "-", &tmp); + if (!vol) + goto out; + ret = glusterd_volinfo_find (vol, &volinfo); + if (ret) + goto out; + } + ret = snprintf (path, path_len, "%s/vols/%s/%s.vol", + priv->workdir, volinfo->volname, volname); + if (ret == -1) + goto out; + + ret = stat (path, &stbuf); + if ((ret == -1) && (errno == ENOENT)) + ret = snprintf (path, path_len, "%s/vols/%s/%s-tcp.vol", + priv->workdir, volinfo->volname, volname); - ret = snprintf (path, path_len, "%s/vols/%s/%s-tcp.vol", - priv->workdir, volname, volname); + ret = 1; +out: + if (dup_volname) + GF_FREE (dup_volname); return ret; } @@ -139,6 +170,8 @@ fail: if (cookie) rsp.op_errno = cookie; + if (!rsp.spec) + rsp.spec = ""; glusterd_submit_reply (req, &rsp, NULL, 0, NULL, (gd_serialize_t)xdr_serialize_getspec_rsp); diff --git a/xlators/mgmt/glusterd/src/glusterd-pmap.c b/xlators/mgmt/glusterd/src/glusterd-pmap.c index 3ae51339398..3a45da000c5 100644 --- a/xlators/mgmt/glusterd/src/glusterd-pmap.c +++ b/xlators/mgmt/glusterd/src/glusterd-pmap.c @@ -125,6 +125,25 @@ pmap_registry_search (xlator_t *this, const char *brickname) } +char * +pmap_registry_search_by_port (xlator_t *this, int port) +{ + struct pmap_registry *pmap = NULL; + char *brickname = NULL; + + if (port > 65535) + goto out; + + pmap = pmap_registry_get (this); + + if (pmap->ports[port].used) + brickname = pmap->ports[port].brickname; + +out: + return brickname; +} + + int pmap_registry_alloc (xlator_t *this) { @@ -171,6 +190,26 @@ out: return 0; } +int +pmap_registry_remove (xlator_t *this, int port, const char *brickname) +{ + struct pmap_registry *pmap = NULL; + int p = 0; + + pmap = pmap_registry_get (this); + + if (port > 65535) + goto out; + + p = port; + pmap->ports[p].used = 0; + if (pmap->ports[p].brickname) + free (pmap->ports[p].brickname); + +out: + return 0; +} + typedef ssize_t (*gfs_serialize_t) (struct iovec outmsg, void *data); @@ -200,7 +239,6 @@ gluster_pmap_portbybrick (rpcsvc_request_t *req) char *brick = NULL; int port = 0; - if (xdr_to_glusterfs_req (req, &args, xdr_to_pmap_port_by_brick_req)) { req->rpc_err = GARBAGE_ARGS; goto fail; @@ -229,13 +267,16 @@ gluster_pmap_brickbyport (rpcsvc_request_t *req) pmap_brick_by_port_req args = {0,}; pmap_brick_by_port_rsp rsp = {0,}; - if (xdr_to_glusterfs_req (req, &args, xdr_to_pmap_brick_by_port_req)) { req->rpc_err = GARBAGE_ARGS; goto fail; } - + rsp.brick = pmap_registry_search_by_port (THIS, args.port); + if (!rsp.brick) { + rsp.op_ret = -1; + rsp.brick = ""; + } fail: glusterd_submit_reply (req, &rsp, NULL, 0, NULL, @@ -258,6 +299,7 @@ gluster_pmap_signup (rpcsvc_request_t *req) goto fail; } + rsp.op_ret = pmap_registry_bind (THIS, args.port, args.brick); fail: glusterd_submit_reply (req, &rsp, NULL, 0, NULL, @@ -273,13 +315,14 @@ gluster_pmap_signin (rpcsvc_request_t *req) pmap_signin_req args = {0,}; pmap_signin_rsp rsp = {0,}; - if (xdr_to_glusterfs_req (req, &args, xdr_to_pmap_signin_req)) { req->rpc_err = GARBAGE_ARGS; goto fail; } + rsp.op_ret = pmap_registry_bind (THIS, args.port, args.brick); + fail: glusterd_submit_reply (req, &rsp, NULL, 0, NULL, (gd_serialize_t)xdr_from_pmap_signin_rsp); @@ -302,6 +345,7 @@ gluster_pmap_signout (rpcsvc_request_t *req) goto fail; } + rsp.op_ret = pmap_registry_remove (THIS, args.port, args.brick); fail: glusterd_submit_reply (req, &rsp, NULL, 0, NULL, diff --git a/xlators/mgmt/glusterd/src/glusterd-pmap.h b/xlators/mgmt/glusterd/src/glusterd-pmap.h index dd72012a7dd..4bc4536f84e 100644 --- a/xlators/mgmt/glusterd/src/glusterd-pmap.h +++ b/xlators/mgmt/glusterd/src/glusterd-pmap.h @@ -51,5 +51,6 @@ struct pmap_registry { int pmap_registry_alloc (xlator_t *this); int pmap_registry_bind (xlator_t *this, int port, const char *brickname); +int pmap_registry_remove (xlator_t *this, int port, const char *brickname); #endif diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index beb4185835b..4202f271638 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -763,16 +763,18 @@ glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo, port = pmap_registry_alloc (THIS); GLUSTERD_GET_BRICK_PIDFILE (pidfile, path, brickinfo->hostname, count); - snprintf (volfile, PATH_MAX, "%s/%s-%s-%d.vol", path, - brickinfo->hostname, volinfo->volname, count); + snprintf (volfile, PATH_MAX, "%s-%s-%d", brickinfo->hostname, + volinfo->volname, count); snprintf (cmd_str, 8192, - "glusterfs --xlator-option server-*.listen-port=%d -f %s -p %s", - port, volfile, pidfile); + "glusterfs --xlator-option server-*.listen-port=%d " + "-s localhost --volfile-id %s -p %s --brick-name %s " + "--brick-port %d", + port, volfile, pidfile, brickinfo->path, port); ret = system (cmd_str); if (ret == 0) { - pmap_registry_bind (THIS, port, brickinfo->path); + //pmap_registry_bind (THIS, port, brickinfo->path); brickinfo->port = port; } out: @@ -832,6 +834,8 @@ glusterd_volume_stop_glusterfs (glusterd_volinfo_t *volinfo, goto out; } + //pmap_registry_remove (THIS, brickinfo->port, brickinfo->path); + ret = unlink (pidfile); if (ret) { -- cgit