summaryrefslogtreecommitdiffstats
path: root/src/providers
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2015-09-04 09:27:17 +0200
committerJakub Hrozek <jhrozek@redhat.com>2015-09-21 17:04:00 +0200
commit99c5f2f6ba0af6ce52be0d82ec2794bacc215742 (patch)
treea538978333a21269e985033b853589919fd6ae41 /src/providers
parentb5825c74b6bf7a99ae2172392dbecb51179013a6 (diff)
downloadsssd-99c5f2f6ba0af6ce52be0d82ec2794bacc215742.tar.gz
sssd-99c5f2f6ba0af6ce52be0d82ec2794bacc215742.tar.xz
sssd-99c5f2f6ba0af6ce52be0d82ec2794bacc215742.zip
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. Reviewed-by: Pavel Březina <pbrezina@redhat.com>
Diffstat (limited to 'src/providers')
-rw-r--r--src/providers/data_provider_be.c102
-rw-r--r--src/providers/dp_backend.h1
2 files changed, 94 insertions, 9 deletions
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index d71a69cb8..effa185f9 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,82 @@ 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_ACTIVE;
+}
+
+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 inactive\n");
+ return;
+ case DOM_ACTIVE:
+ DEBUG(SSSDBG_TRACE_LIBS,
+ "Marking subdomain %s as inactive\n", subdom->name);
+ 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_ACTIVE);
+ }
+ }
+}
+
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 bca0c2f97..4bffcee9e 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,