From 3551dd5c2c2c75ce68ef95b91fc2420f17c92b92 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Mon, 21 Sep 2015 12:31:18 +0200 Subject: [PATCH 94/96] FO: Add an API to reset all servers in a single service Required for: https://fedorahosted.org/sssd/ticket/2639 Previously, we had a function that allowed the caller to reset the status of all services in the global fail over context. This patch adds a new function that allows the caller to reset a single service instead. The main user would be IPA subdomain provider that might need to reset the status of an AD trusted domain on demand. Reviewed-by: Sumit Bose (cherry picked from commit 3ac3b5746f08970c109664b95340c556057e3c6a) --- src/providers/data_provider_fo.c | 19 +++++++++++++++++++ src/providers/dp_backend.h | 1 + src/providers/fail_over.c | 30 ++++++++++++++++++++---------- src/providers/fail_over.h | 2 ++ 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/providers/data_provider_fo.c b/src/providers/data_provider_fo.c index 41d70de065260f31dcea4c2b664a1f436823ccc1..cd57340a0ba0ac7e474dc502bf1f1b4de0e1f778 100644 --- a/src/providers/data_provider_fo.c +++ b/src/providers/data_provider_fo.c @@ -743,6 +743,25 @@ void reset_fo(struct be_ctx *be_ctx) fo_reset_services(be_ctx->be_fo->fo_ctx); } +void be_fo_reset_svc(struct be_ctx *be_ctx, + const char *svc_name) +{ + struct fo_service *service; + int ret; + + DEBUG(SSSDBG_TRACE_LIBS, + "Resetting all servers in service %s\n", svc_name); + + ret = fo_get_service(be_ctx->be_fo->fo_ctx, svc_name, &service); + if (ret != EOK) { + DEBUG(SSSDBG_MINOR_FAILURE, + "Cannot retrieve service [%s]\n", svc_name); + return; + } + + fo_reset_servers(service); +} + void _be_fo_set_port_status(struct be_ctx *ctx, const char *service_name, struct fo_server *server, diff --git a/src/providers/dp_backend.h b/src/providers/dp_backend.h index 4bffcee9e8739302343b7813d3540eb43e966581..0ced851be8468ce21a9d283e26461fc47194557e 100644 --- a/src/providers/dp_backend.h +++ b/src/providers/dp_backend.h @@ -283,6 +283,7 @@ int be_fo_run_callbacks_at_next_request(struct be_ctx *ctx, const char *service_name); void reset_fo(struct be_ctx *be_ctx); +void be_fo_reset_svc(struct be_ctx *be_ctx, const char *svc_name); errno_t be_res_init(struct be_ctx *ctx); diff --git a/src/providers/fail_over.c b/src/providers/fail_over.c index 6d835ae0efdfdf96532e8458e12238ba17910a4f..562f0b3fd7870387a80c889b245cda0d39dea509 100644 --- a/src/providers/fail_over.c +++ b/src/providers/fail_over.c @@ -1547,21 +1547,31 @@ time_t fo_get_service_retry_timeout(struct fo_service *svc) return svc->ctx->opts->retry_timeout; } +void fo_reset_servers(struct fo_service *service) +{ + struct fo_server *server; + + DLIST_FOR_EACH(server, service->server_list) { + if (server->srv_data != NULL) { + set_srv_data_status(server->srv_data, SRV_NEUTRAL); + } else { + fo_set_server_status(server, SERVER_NAME_NOT_RESOLVED); + } + + fo_set_port_status(server, PORT_NEUTRAL); + } +} + + void fo_reset_services(struct fo_ctx *fo_ctx) { struct fo_service *service; - struct fo_server *server; + + DEBUG(SSSDBG_TRACE_LIBS, + "Resetting all servers in all services\n"); DLIST_FOR_EACH(service, fo_ctx->service_list) { - DLIST_FOR_EACH(server, service->server_list) { - if (server->srv_data != NULL) { - set_srv_data_status(server->srv_data, SRV_NEUTRAL); - } else { - fo_set_server_status(server, SERVER_NAME_NOT_RESOLVED); - } - - fo_set_port_status(server, PORT_NEUTRAL); - } + fo_reset_servers(service); } } diff --git a/src/providers/fail_over.h b/src/providers/fail_over.h index d44ad2ff145dc6b3617e6f2ea665c7d82d923ddb..e49c6414a14eb6ca2cad333f8efbb58576811345 100644 --- a/src/providers/fail_over.h +++ b/src/providers/fail_over.h @@ -198,6 +198,8 @@ time_t fo_get_service_retry_timeout(struct fo_service *svc); void fo_reset_services(struct fo_ctx *fo_ctx); +void fo_reset_servers(struct fo_service *svc); + bool fo_svc_has_server(struct fo_service *service, struct fo_server *server); /* -- 2.4.3