>From 591d07855b70aacbb4488ba9a54438ee9ded48b5 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Fri, 4 Sep 2015 09:27:17 +0200 Subject: [PATCH 2/8] DP: Provide a way to mark subdomain as disabled and auto-enable it later with offline_timeout https://fedorahosted.org/sssd/ticket/2637 Adds a new Data Provider function be_mark_dom_offline() that is a replacement for be_mark_offline(). When called, the function would either set the whole back end offline, just like be_mark_offline or just set the subdomain status to inactive. When a subdomain is inactive, there is a singleton timed task that would re-set the subdomin after offline_timeout seconds. --- src/providers/data_provider_be.c | 99 ++++++++++++++++++++++++++++++++++++---- src/providers/dp_backend.h | 1 + 2 files changed, 91 insertions(+), 9 deletions(-) diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c index d147630248f0a24f5a632760b55b9284a6928e40..42778580b691ece990442912a75e5578e7d62268 100644 --- a/src/providers/data_provider_be.c +++ b/src/providers/data_provider_be.c @@ -478,6 +478,24 @@ try_to_go_online(TALLOC_CTX *mem_ctx, return EOK; } +static int get_offline_timeout(struct be_ctx *ctx) +{ + errno_t ret; + int offline_timeout; + + ret = confdb_get_int(ctx->cdb, ctx->conf_path, + CONFDB_DOMAIN_OFFLINE_TIMEOUT, 60, + &offline_timeout); + if (ret != EOK) { + DEBUG(SSSDBG_CRIT_FAILURE, + "Failed to get offline_timeout from confdb. " + "Will use 60 seconds.\n"); + offline_timeout = 60; + } + + return offline_timeout; +} + void be_mark_offline(struct be_ctx *ctx) { int offline_timeout; @@ -493,15 +511,9 @@ void be_mark_offline(struct be_ctx *ctx) /* This is the first time we go offline - create a periodic task * to check if we can switch to online. */ DEBUG(SSSDBG_TRACE_INTERNAL, "Initialize check_if_online_ptask.\n"); - ret = confdb_get_int(ctx->cdb, ctx->conf_path, - CONFDB_DOMAIN_OFFLINE_TIMEOUT, 60, - &offline_timeout); - if (ret != EOK) { - DEBUG(SSSDBG_CRIT_FAILURE, - "Failed to get offline_timeout from confdb. " - "Will use 60 seconds.\n"); - offline_timeout = 60; - } + + offline_timeout = get_offline_timeout(ctx); + ret = be_ptask_create_sync(ctx, ctx, offline_timeout, offline_timeout, offline_timeout, 30, offline_timeout, @@ -524,10 +536,79 @@ void be_mark_offline(struct be_ctx *ctx) be_run_offline_cb(ctx); } +static void be_subdom_reset_status(struct tevent_context *ev, + struct tevent_timer *te, + struct timeval current_time, + void *pvt) +{ + struct sss_domain_info *subdom = talloc_get_type(pvt, + struct sss_domain_info); + + DEBUG(SSSDBG_TRACE_LIBS, "Resetting subdomain %s\n", subdom->name); + subdom->state = DOM_ENABLED; +} + +static void be_mark_subdom_offline(struct sss_domain_info *subdom, + struct be_ctx *be_ctx) +{ + struct timeval tv; + struct tevent_timer *timeout = NULL; + int reset_status_timeout; + + reset_status_timeout = get_offline_timeout(be_ctx); + tv = tevent_timeval_current_ofs(reset_status_timeout, 0); + + switch (subdom->state) { + case DOM_DISABLED: + DEBUG(SSSDBG_MINOR_FAILURE, "Won't touch disabled subdomain\n"); + return; + case DOM_INACTIVE: + DEBUG(SSSDBG_TRACE_ALL, "Subdomain already disabled\n"); + return; + case DOM_ENABLED: + break; + } + + timeout = tevent_add_timer(be_ctx->ev, be_ctx, tv, + be_subdom_reset_status, subdom); + if (timeout == NULL) { + DEBUG(SSSDBG_OP_FAILURE, "Cannot create timer\n"); + return; + } + + subdom->state = DOM_INACTIVE; +} + +void be_mark_dom_offline(struct sss_domain_info *dom, struct be_ctx *ctx) +{ + if (IS_SUBDOMAIN(dom) == false) { + DEBUG(SSSDBG_TRACE_LIBS, "Marking back end offline\n"); + be_mark_offline(ctx); + } else { + DEBUG(SSSDBG_TRACE_LIBS, "Marking subdomain %s offline\n", dom->name); + be_mark_subdom_offline(dom, ctx); + } +} + +static void reactivate_subdoms(struct sss_domain_info *head) +{ + struct sss_domain_info *dom; + + DEBUG(SSSDBG_TRACE_LIBS, "Resetting all subdomains"); + + for (dom = head; dom; dom = get_next_domain(dom, true)) { + if (sss_domain_get_state(dom) == DOM_INACTIVE) { + sss_domain_set_state(dom, DOM_ENABLED); + } + } +} static void be_reset_offline(struct be_ctx *ctx) { ctx->offstat.went_offline = 0; ctx->offstat.offline = false; + + reactivate_subdoms(ctx->domain); + be_ptask_disable(ctx->check_if_online_ptask); be_run_online_cb(ctx); } diff --git a/src/providers/dp_backend.h b/src/providers/dp_backend.h index bca0c2f97691a96086555482ce181dbdf684466b..4bffcee9e8739302343b7813d3540eb43e966581 100644 --- a/src/providers/dp_backend.h +++ b/src/providers/dp_backend.h @@ -189,6 +189,7 @@ struct be_host_req { bool be_is_offline(struct be_ctx *ctx); void be_mark_offline(struct be_ctx *ctx); +void be_mark_dom_offline(struct sss_domain_info *dom, struct be_ctx *ctx); int be_add_reconnect_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, -- 2.4.3