diff options
-rw-r--r-- | glusterfsd/src/fetch-spec.c | 6 | ||||
-rw-r--r-- | glusterfsd/src/glusterfsd.c | 16 | ||||
-rw-r--r-- | glusterfsd/src/glusterfsd.h | 1 | ||||
-rw-r--r-- | libglusterfs/src/glusterfs.h | 1 | ||||
-rw-r--r-- | xlators/protocol/client/src/client-protocol.c | 7 |
5 files changed, 30 insertions, 1 deletions
diff --git a/glusterfsd/src/fetch-spec.c b/glusterfsd/src/fetch-spec.c index f914a416dd4..3e9712d8db4 100644 --- a/glusterfsd/src/fetch-spec.c +++ b/glusterfsd/src/fetch-spec.c @@ -71,6 +71,7 @@ fetch_notify (xlator_t *this_xl, int event, void *data, ...) { int ret = 0; call_frame_t *frame = NULL; + static int failed_connects = 0; switch (event) { @@ -85,6 +86,11 @@ fetch_notify (xlator_t *this_xl, int event, void *data, ...) 0); break; case GF_EVENT_CHILD_DOWN: + failed_connects++; + if (failed_connects + >= this_xl->ctx->cmd_args.max_connect_attempts) { + exit (1); + } break; default: ret = default_notify (this_xl, event, data); diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c index 37eefa01bec..d4ac16a3083 100644 --- a/glusterfsd/src/glusterfsd.c +++ b/glusterfsd/src/glusterfsd.c @@ -85,6 +85,10 @@ static struct argp_option gf_options[] = { {"volfile-server", ARGP_VOLFILE_SERVER_KEY, "SERVER", 0, "Server to get the volume file from. This option overrides " "--volfile option"}, + {"volfile-max-fetch-attempts", ARGP_VOLFILE_MAX_FETCH_ATTEMPTS, + "MAX-ATTEMPTS", 0, "Maximum number of connect attempts to server. " + "This option should be provided with --volfile-server option" + "[default: 1]"}, {"volfile", ARGP_VOLUME_FILE_KEY, "VOLFILE", 0, "File to use as VOLUME_FILE [default: "DEFAULT_CLIENT_VOLUME_FILE" or " DEFAULT_SERVER_VOLUME_FILE"]"}, @@ -659,7 +663,19 @@ parse_opts (int key, char *arg, struct argp_state *state) case ARGP_VOLFILE_SERVER_KEY: cmd_args->volfile_server = strdup (arg); break; + + case ARGP_VOLFILE_MAX_FETCH_ATTEMPTS: + n = 0; + if (gf_string2uint_base10 (arg, &n) == 0) { + cmd_args->max_connect_attempts = n; + break; + } + + argp_failure (state, -1, 0, + "Invalid limit on connect attempts %s", arg); + break; + case ARGP_VOLUME_FILE_KEY: cmd_args->volume_file = strdup (arg); break; diff --git a/glusterfsd/src/glusterfsd.h b/glusterfsd/src/glusterfsd.h index 0d6423ab487..e06526b0664 100644 --- a/glusterfsd/src/glusterfsd.h +++ b/glusterfsd/src/glusterfsd.h @@ -71,6 +71,7 @@ enum argp_option_keys { #endif /* DARWIN */ ARGP_VOLFILE_ID_KEY = 143, ARGP_VOLFILE_CHECK_KEY = 144, + ARGP_VOLFILE_MAX_FETCH_ATTEMPTS = 145, }; /* Moved here from fetch-spec.h */ diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index b828a3ecd7a..604b41d1488 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -218,6 +218,7 @@ struct _cmd_args { char *volume_file; gf_loglevel_t log_level; char *log_file; + int32_t max_connect_attempts; /* advanced options */ uint32_t volfile_server_port; char *volfile_server_transport; diff --git a/xlators/protocol/client/src/client-protocol.c b/xlators/protocol/client/src/client-protocol.c index e7fda9f0eea..55afa11e1e6 100644 --- a/xlators/protocol/client/src/client-protocol.c +++ b/xlators/protocol/client/src/client-protocol.c @@ -6228,6 +6228,7 @@ client_protocol_reconnect (void *trans_ptr) transport_t *trans = NULL; client_connection_t *conn = NULL; struct timeval tv = {0, 0}; + int32_t ret = 0; trans = trans_ptr; conn = trans->xl_private; @@ -6243,7 +6244,7 @@ client_protocol_reconnect (void *trans_ptr) gf_log (trans->xl->name, GF_LOG_DEBUG, "attempting reconnect"); - transport_connect (trans); + ret = transport_connect (trans); conn->reconnect = gf_timer_call_after (trans->xl->ctx, tv, @@ -6255,6 +6256,10 @@ client_protocol_reconnect (void *trans_ptr) } } pthread_mutex_unlock (&conn->lock); + + if (ret == -1) { + default_notify (trans->xl, GF_EVENT_CHILD_DOWN, NULL); + } } int |