diff options
-rw-r--r-- | api/src/glfs-mem-types.h | 2 | ||||
-rw-r--r-- | api/src/glfs-mgmt.c | 88 | ||||
-rw-r--r-- | api/src/glfs.c | 124 | ||||
-rw-r--r-- | api/src/glfs.h | 31 | ||||
-rw-r--r-- | libglusterfs/src/glusterfs.h | 2 |
5 files changed, 193 insertions, 54 deletions
diff --git a/api/src/glfs-mem-types.h b/api/src/glfs-mem-types.h index 3301b3da537..76f4fc774cc 100644 --- a/api/src/glfs-mem-types.h +++ b/api/src/glfs-mem-types.h @@ -23,10 +23,10 @@ enum glfs_mem_types_ { glfs_mt_glfs_io_t, glfs_mt_volfile_t, glfs_mt_xlator_cmdline_option_t, + glfs_mt_server_cmdline_t, glfs_mt_glfs_object_t, glfs_mt_readdirbuf_t, glfs_mt_end }; #endif - diff --git a/api/src/glfs-mgmt.c b/api/src/glfs-mgmt.c index 6843e9cb3fe..5493e89db81 100644 --- a/api/src/glfs-mgmt.c +++ b/api/src/glfs-mgmt.c @@ -413,32 +413,81 @@ mgmt_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, void *data) { xlator_t *this = NULL; - cmd_args_t *cmd_args = NULL; glusterfs_ctx_t *ctx = NULL; struct glfs *fs = NULL; int ret = 0; + server_cmdline_t *server = NULL; + rpc_transport_t *rpc_trans = NULL; + + this = mydata; + rpc_trans = rpc->conn.trans; + + ctx = this->ctx; + fs = ((xlator_t *)ctx->master)->private; + + switch (event) { + case RPC_CLNT_DISCONNECT: + if (!ctx->active) { + gf_log ("glfs-mgmt", GF_LOG_ERROR, + "failed to connect with remote-host: %s (%s)", + ctx->cmd_args.volfile_server, + strerror (errno)); + server = ctx->cmd_args.curr_server; + if (server->list.next == &ctx->cmd_args.volfile_servers) { + errno = ENOTCONN; + gf_log("glfs-mgmt", GF_LOG_INFO, + "Exhausted all volfile servers"); + glfs_init_done (fs, -1); + break; + } + server = list_entry (server->list.next, typeof(*server), + list); + ctx->cmd_args.curr_server = server; + ctx->cmd_args.volfile_server_port = server->port; + ctx->cmd_args.volfile_server = server->volfile_server; + ctx->cmd_args.volfile_server_transport = server->transport; + ret = dict_set_int32 (rpc_trans->options, + "remote-port", + server->port); + if (ret != 0) { + gf_log ("glfs-mgmt", GF_LOG_ERROR, + "failed to set remote-port: %d", + server->port); + errno = ENOTCONN; + glfs_init_done (fs, -1); + break; + } - this = mydata; - ctx = this->ctx; - fs = ((xlator_t *)ctx->master)->private; - cmd_args = &ctx->cmd_args; + ret = dict_set_str (rpc_trans->options, + "remote-host", + server->volfile_server); + if (ret != 0) { + gf_log ("glfs-mgmt", GF_LOG_ERROR, + "failed to set remote-host: %s", + server->volfile_server); + errno = ENOTCONN; + glfs_init_done (fs, -1); + break; + } - switch (event) { - case RPC_CLNT_DISCONNECT: - if (!ctx->active) { - cmd_args->max_connect_attempts--; - gf_log ("glfs-mgmt", GF_LOG_ERROR, - "failed to connect with remote-host: %s", - strerror (errno)); - gf_log ("glfs-mgmt", GF_LOG_INFO, - "%d connect attempts left", - cmd_args->max_connect_attempts); - if (0 >= cmd_args->max_connect_attempts) { + ret = dict_set_str (rpc_trans->options, + "transport-type", + server->transport); + if (ret != 0) { + gf_log ("glfs-mgmt", GF_LOG_ERROR, + "failed to set transport-type: %s", + server->transport); errno = ENOTCONN; - glfs_init_done (fs, -1); + glfs_init_done (fs, -1); + break; } - } - break; + gf_log ("glfs-mgmt", GF_LOG_INFO, + "connecting to next volfile server %s" + " at port %d with transport: %s", + server->volfile_server, server->port, + server->transport); + } + break; case RPC_CLNT_CONNECT: rpc_clnt_set_connected (&((struct rpc_clnt*)ctx->mgmt)->conn); @@ -540,4 +589,3 @@ glfs_mgmt_init (struct glfs *fs) out: return ret; } - diff --git a/api/src/glfs.c b/api/src/glfs.c index 1bae78d2378..069b7aa23fa 100644 --- a/api/src/glfs.c +++ b/api/src/glfs.c @@ -127,6 +127,8 @@ glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx) INIT_LIST_HEAD (&pool->all_frames); INIT_LIST_HEAD (&ctx->cmd_args.xlator_options); + INIT_LIST_HEAD (&ctx->cmd_args.volfile_servers); + LOCK_INIT (&pool->lock); ctx->pool = pool; @@ -317,6 +319,108 @@ enomem: return -1; } +int +glfs_unset_volfile_server (struct glfs *fs, const char *transport, + const char *host, const int port) +{ + cmd_args_t *cmd_args = NULL; + server_cmdline_t *server = NULL; + int ret = -1; + + if (!transport || !host || !port) { + errno = EINVAL; + return ret; + } + + cmd_args = &fs->ctx->cmd_args; + list_for_each_entry(server, &cmd_args->curr_server->list, list) { + if ((!strcmp(server->volfile_server, host) && + !strcmp(server->transport, transport) && + (server->port == port))) { + list_del (&server->list); + ret = 0; + goto out; + } + } + +out: + return ret; +} + +int +glfs_set_volfile_server (struct glfs *fs, const char *transport, + const char *host, int port) +{ + cmd_args_t *cmd_args = NULL; + server_cmdline_t *server = NULL; + server_cmdline_t *tmp = NULL; + int ret = -1; + + if (!transport || !host || !port) { + errno = EINVAL; + return ret; + } + + cmd_args = &fs->ctx->cmd_args; + + cmd_args->max_connect_attempts = 1; + + server = GF_CALLOC (1, sizeof (server_cmdline_t), + glfs_mt_server_cmdline_t); + + if (!server) { + errno = ENOMEM; + goto out; + } + + INIT_LIST_HEAD (&server->list); + + server->volfile_server = gf_strdup (host); + if (!server->volfile_server) { + errno = ENOMEM; + goto out; + } + + server->transport = gf_strdup (transport); + if (!server->transport) { + errno = ENOMEM; + goto out; + } + + server->port = port; + + if (!cmd_args->volfile_server) { + cmd_args->volfile_server = server->volfile_server; + cmd_args->volfile_server_transport = server->transport; + cmd_args->volfile_server_port = server->port; + cmd_args->curr_server = server; + } + + list_for_each_entry(tmp, &cmd_args->volfile_servers, list) { + if ((!strcmp(tmp->volfile_server, host) && + !strcmp(tmp->transport, transport) && + (tmp->port == port))) { + errno = EEXIST; + ret = -1; + goto out; + } + } + + list_add_tail (&server->list, &cmd_args->volfile_servers); + + ret = 0; +out: + if (ret == -1) { + if (server) { + GF_FREE (server->volfile_server); + GF_FREE (server->transport); + GF_FREE (server); + } + } + + return ret; +} + int glfs_setfsuid (uid_t fsuid) { return syncopctx_setfsuid (&fsuid); @@ -469,26 +573,6 @@ glfs_set_volfile (struct glfs *fs, const char *volfile) int -glfs_set_volfile_server (struct glfs *fs, const char *transport, - const char *host, int port) -{ - cmd_args_t *cmd_args = NULL; - - cmd_args = &fs->ctx->cmd_args; - - if (vol_assigned (cmd_args)) - return -1; - - cmd_args->volfile_server = gf_strdup (host); - cmd_args->volfile_server_transport = gf_strdup (transport); - cmd_args->volfile_server_port = port; - cmd_args->max_connect_attempts = 2; - - return 0; -} - - -int glfs_set_logging (struct glfs *fs, const char *logfile, int loglevel) { int ret = 0; diff --git a/api/src/glfs.h b/api/src/glfs.h index bf298ce47a6..2210c26d34f 100644 --- a/api/src/glfs.h +++ b/api/src/glfs.h @@ -115,12 +115,12 @@ int glfs_set_volfile (glfs_t *fs, const char *volfile); /* SYNOPSIS - glfs_set_volfile_server: Specify the address of management server. + glfs_set_volfile_server: Specify the list of addresses for management server. DESCRIPTION - This function specifies the address of the management server (glusterd) - to connect, and establish the volume configuration. The @volname + This function specifies the list of addresses for the management server + (glusterd) to connect, and establish the volume configuration. The @volname parameter passed to glfs_new() is the volume which will be virtually mounted as the glfs_t object. All operations performed by the CLI at the management server will automatically be reflected in the 'virtual @@ -136,19 +136,22 @@ int glfs_set_volfile (glfs_t *fs, const char *volfile); @transport: String specifying the transport used to connect to the management daemon. Specifying NULL will result in the usage - of the default (tcp) transport type. Permitted values - are those what you specify as transport-type in a volume - specification file (e.g "tcp", "rdma", "unix".) + of the default (tcp) transport type. Permitted values + are those what you specify as transport-type in a volume + specification file (e.g "tcp", "rdma" etc.) - @host: String specifying the address of where to find the management - daemon. Depending on the transport type this would either be - an FQDN (e.g: "storage01.company.com"), ASCII encoded IP - address "192.168.22.1", or a UNIX domain socket path (e.g - "/tmp/glusterd.socket".) + @host: String specifying the address where to find the management daemon. + This would either be + - FQDN (e.g: "storage01.company.com") or + - ASCII (e.g: "192.168.22.1") + + NOTE: This API is special, multiple calls to this function with different + volfile servers, port or transport-type would create a list of volfile + servers which would be polled during `volfile_fetch_attempts()` @port: The TCP port number where gluster management daemon is listening. Specifying 0 uses the default port number GF_DEFAULT_BASE_PORT. - This parameter is unused if you are using a UNIX domain socket. + This parameter is unused if you are using a UNIX domain socket. RETURN VALUES @@ -158,8 +161,10 @@ int glfs_set_volfile (glfs_t *fs, const char *volfile); */ int glfs_set_volfile_server (glfs_t *fs, const char *transport, - const char *host, int port); + const char *host, int port); +int glfs_unset_volfile_server (glfs_t *fs, const char *transport, + const char *host, int port) __THROW; /* SYNOPSIS diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index 2b26763644b..9aa3817228a 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -322,6 +322,8 @@ typedef struct _xlator_cmdline_option xlator_cmdline_option_t; struct _server_cmdline { struct list_head list; char *volfile_server; + char *transport; + int port; }; typedef struct _server_cmdline server_cmdline_t; |