diff options
author | Raghavendra Talur <rtalur@redhat.com> | 2015-09-07 14:29:15 +0530 |
---|---|---|
committer | Niels de Vos <ndevos@redhat.com> | 2015-09-28 04:55:08 -0700 |
commit | 007bfd963240d7cf80b4f1b5f652cf142bcadb65 (patch) | |
tree | c32fe1393b9e4fd824ff2a2f8c5c9337c27b7f97 | |
parent | ecfa2edd7816abbf8fbbe43c308ddf895849e8e6 (diff) |
gfapi: transport and port are optional for glfs_set_volfile_server
Only server is the required argument for glfs_set_volfile_server
and both transport and port are optional. When glfs_set_volfile_server
is invocated multiple times, only on the first invocation we replace
port 0 with 24007 and transport NULL with "tcp".
Hence, replacing the parameters at the entry function is the right way.
Change-Id: If9f4a5f7fd9038eed140e2f47167a8fd11acc2f6
BUG: 1260561
Signed-off-by: Raghavendra Talur <rtalur@redhat.com>
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Reviewed-on: http://review.gluster.org/12114
Tested-by: NetBSD Build System <jenkins@build.gluster.org>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
-rw-r--r-- | api/src/glfs.c | 55 | ||||
-rw-r--r-- | libglusterfs/src/globals.h | 1 |
2 files changed, 44 insertions, 12 deletions
diff --git a/api/src/glfs.c b/api/src/glfs.c index 490dbde9c1e..18f5c8f913f 100644 --- a/api/src/glfs.c +++ b/api/src/glfs.c @@ -351,9 +351,12 @@ pub_glfs_unset_volfile_server (struct glfs *fs, const char *transport, { cmd_args_t *cmd_args = NULL; server_cmdline_t *server = NULL; + server_cmdline_t *tmp = NULL; + char *transport_val = NULL; + int port_val = 0; int ret = -1; - if (!transport || !host || !port) { + if (!fs || !host) { errno = EINVAL; return ret; } @@ -362,10 +365,30 @@ pub_glfs_unset_volfile_server (struct glfs *fs, const char *transport, __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); cmd_args = &fs->ctx->cmd_args; - list_for_each_entry(server, &cmd_args->curr_server->list, list) { + + if (transport) { + transport_val = gf_strdup (transport); + } else { + transport_val = gf_strdup (GF_DEFAULT_VOLFILE_TRANSPORT); + } + + if (!transport_val) { + errno = ENOMEM; + goto out; + } + + if (port) { + port_val = port; + } else { + port_val = GF_DEFAULT_BASE_PORT; + } + + list_for_each_entry_safe (server, tmp, + &cmd_args->curr_server->list, + list) { if ((!strcmp(server->volfile_server, host) && - !strcmp(server->transport, transport) && - (server->port == port))) { + !strcmp(server->transport, transport_val) && + (server->port == port_val))) { list_del (&server->list); ret = 0; goto out; @@ -373,6 +396,7 @@ pub_glfs_unset_volfile_server (struct glfs *fs, const char *transport, } out: + GF_FREE (transport_val); __GLFS_EXIT_FS; invalid_fs: @@ -421,13 +445,20 @@ pub_glfs_set_volfile_server (struct glfs *fs, const char *transport, if (transport) { server->transport = gf_strdup (transport); - if (!server->transport) { - errno = ENOMEM; - goto out; - } + } else { + server->transport = gf_strdup (GF_DEFAULT_VOLFILE_TRANSPORT); } - server->port = port; + if (!server->transport) { + errno = ENOMEM; + goto out; + } + + if (port) { + server->port = port; + } else { + server->port = GF_DEFAULT_BASE_PORT; + } if (!cmd_args->volfile_server) { cmd_args->volfile_server = server->volfile_server; @@ -437,9 +468,9 @@ pub_glfs_set_volfile_server (struct glfs *fs, const char *transport, } list_for_each_entry(tmp, &cmd_args->volfile_servers, list) { - if ((!strcmp(tmp->volfile_server, host) && - !strcmp(tmp->transport, transport) && - (tmp->port == port))) { + if ((!strcmp(tmp->volfile_server, server->volfile_server) && + !strcmp(tmp->transport, server->transport) && + (tmp->port == server->port))) { errno = EEXIST; ret = -1; goto out; diff --git a/libglusterfs/src/globals.h b/libglusterfs/src/globals.h index 46c9ca27f6c..976302e73f9 100644 --- a/libglusterfs/src/globals.h +++ b/libglusterfs/src/globals.h @@ -12,6 +12,7 @@ #define _GLOBALS_H #define GF_DEFAULT_BASE_PORT 24007 +#define GF_DEFAULT_VOLFILE_TRANSPORT "tcp" #define GD_OP_VERSION_KEY "operating-version" #define GD_MIN_OP_VERSION_KEY "minimum-operating-version" |