diff options
author | eindenbom <eindenbom@gmail.com> | 2010-07-02 18:46:53 +0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2010-07-09 11:44:06 -0400 |
commit | 54577e54d1b6300aeb348087372c14ed72530f88 (patch) | |
tree | 47af5ec5db8ab7cd430a17545ac563023f02c919 /src/providers/data_provider_fo.c | |
parent | 2d7a7b0140a4d3fcef9148900276e24f82e33866 (diff) | |
download | sssd-54577e54d1b6300aeb348087372c14ed72530f88.tar.gz sssd-54577e54d1b6300aeb348087372c14ed72530f88.tar.xz sssd-54577e54d1b6300aeb348087372c14ed72530f88.zip |
Add an interface to try next fail-over server after connection to the active server was unexpectedly dropped.
Diffstat (limited to 'src/providers/data_provider_fo.c')
-rw-r--r-- | src/providers/data_provider_fo.c | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/src/providers/data_provider_fo.c b/src/providers/data_provider_fo.c index 21059d394..dff0aef24 100644 --- a/src/providers/data_provider_fo.c +++ b/src/providers/data_provider_fo.c @@ -155,22 +155,42 @@ static int be_svc_data_destroy(void *memptr) return 0; } -int be_fo_add_service(struct be_ctx *ctx, const char *service_name) +/* + * Find registered be_svc_data by service name. + */ +static struct be_svc_data *be_fo_find_svc_data(struct be_ctx *ctx, + const char *service_name) { - struct fo_service *service; struct be_svc_data *svc; - int ret; + + if (!ctx || !ctx->be_fo) { + return 0; + } DLIST_FOR_EACH(svc, ctx->be_fo->svcs) { if (strcmp(svc->name, service_name) == 0) { - DEBUG(6, ("Failover service already initialized!\n")); - /* we already have a service up and configured, - * can happen when using both id and auth provider - */ - return EOK; + return svc; } } + return 0; +} + +int be_fo_add_service(struct be_ctx *ctx, const char *service_name) +{ + struct fo_service *service; + struct be_svc_data *svc; + int ret; + + svc = be_fo_find_svc_data(ctx, service_name); + if (svc) { + DEBUG(6, ("Failover service already initialized!\n")); + /* we already have a service up and configured, + * can happen when using both id and auth provider + */ + return EOK; + } + /* if not in the be service list, try to create new one */ ret = fo_new_service(ctx->be_fo->fo_ctx, service_name, &service); @@ -217,11 +237,7 @@ int be_fo_service_add_callback(TALLOC_CTX *memctx, struct be_svc_callback *callback; struct be_svc_data *svc; - DLIST_FOR_EACH(svc, ctx->be_fo->svcs) { - if (strcmp(svc->name, service_name) == 0) { - break; - } - } + svc = be_fo_find_svc_data(ctx, service_name); if (NULL == svc) { return ENOENT; } @@ -249,11 +265,7 @@ int be_fo_add_srv_server(struct be_ctx *ctx, const char *service_name, char *domain; int ret; - DLIST_FOR_EACH(svc, ctx->be_fo->svcs) { - if (strcmp(svc->name, service_name) == 0) { - break; - } - } + svc = be_fo_find_svc_data(ctx, service_name); if (NULL == svc) { return ENOENT; } @@ -281,16 +293,7 @@ int be_fo_get_server_count(struct be_ctx *ctx, const char *service_name) { struct be_svc_data *svc_data; - if (!ctx->be_fo) { - return 0; - } - - DLIST_FOR_EACH(svc_data, ctx->be_fo->svcs) { - if (strcmp(svc_data->name, service_name) == 0) { - break; - } - } - + svc_data = be_fo_find_svc_data(ctx, service_name); if (!svc_data) { return 0; } @@ -304,11 +307,7 @@ int be_fo_add_server(struct be_ctx *ctx, const char *service_name, struct be_svc_data *svc; int ret; - DLIST_FOR_EACH(svc, ctx->be_fo->svcs) { - if (strcmp(svc->name, service_name) == 0) { - break; - } - } + svc = be_fo_find_svc_data(ctx, service_name); if (NULL == svc) { return ENOENT; } @@ -349,19 +348,14 @@ struct tevent_req *be_resolve_server_send(TALLOC_CTX *memctx, state->ev = ev; state->ctx = ctx; - DLIST_FOR_EACH(svc, ctx->be_fo->svcs) { - if (strcmp(svc->name, service_name) == 0) { - state->svc = svc; - break; - } - } - + svc = be_fo_find_svc_data(ctx, service_name); if (NULL == svc) { tevent_req_error(req, EINVAL); tevent_req_post(req, ev); return req; } + state->svc = svc; state->attempts = 0; subreq = fo_resolve_service_send(state, ev, @@ -474,16 +468,22 @@ int be_resolve_server_recv(struct tevent_req *req, struct fo_server **srv) return EOK; } +void be_fo_try_next_server(struct be_ctx *ctx, const char *service_name) +{ + struct be_svc_data *svc; + + svc = be_fo_find_svc_data(ctx, service_name); + if (svc) { + fo_try_next_server(svc->fo_service); + } +} + int be_fo_run_callbacks_at_next_request(struct be_ctx *ctx, const char *service_name) { struct be_svc_data *svc; - DLIST_FOR_EACH(svc, ctx->be_fo->svcs) { - if (strcmp(svc->name, service_name) == 0) { - break; - } - } + svc = be_fo_find_svc_data(ctx, service_name); if (NULL == svc) { return ENOENT; } |